When you do startActivity()
with chooser, Android would list all apps entitled to handle your Intent
along with options to set this assignment permanent or once-time (on ICS its Always
and Just once
action button, on 2.x it's acheckbox). However for this code:
public class Redirector {
public static void showActivityWithChooser( Context context, int chooserLabelTitleId, Intent intent ) {
try {
context.startActivity( Intent.createChooser( intent,
context.getResources().getString( chooserLabelTitleId )) );
} catch( Exception e ) {
e.printStackTrace();
}
}
public static void viewInExternalApplication( Context context, String url ) {
Intent intent = new Intent( Intent.ACTION_VIEW );
intent.setData( Uri.parse( url ) );
intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET );
showActivityWithChooser( context, R.string.open_chooser_title, intent );
}
}
I see no Always | Just once
buttons and cannot make my selection permanent. What elementary I overlooked that made Android unable to make user choice persistent?
See the pics: left dialog is what I'd like to see, but right is what I get now (different number of applications in both dialogs is irrelevant):
For a record - it was over-interpretation type of bug (of mine). The chooser I was using is exactly what can be seen on the image on the right side. And it was showing up all the time because... I was calling it all the time. I incorrectly assumed that chooser offers Always | Just once
functionality and would not show up if user tapped "Always" (and will show up if s/he used Just once
). But it is wrong. Chooser will always show up because that's its role - to let user choose.
The Always | Just once
functionality is different thing -> it is a feature of the Android framework for startActivity()
(and startActivityForResult()
etc) and it would show up automatically when needed (when there's more than one app, or precisely, more than one matching intent-filter
declared in app manifest, that matches certain Intent
). It would not show up if you got just one (or if user already choose Always
).
So you, as developer do not need to care nor handle the case in any special way. To fix the issue I simply changed my viewInExternalApplication()
code to just call startActivity()
:
try {
context.startActivity( intent );
} catch (.... )
and let the framework do the rest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With