Reputation: 723
In one of my apps I want to ask a user to choose a web browser, and want the options "Once" and "Always" be available to them.
Right now I am using:
Intent webIntent = new Intent(Intent.ACTION_VIEW);
webIntent.setData(Uri.parse("http://www.google.com"));
webIntent.setComponent(new ComponentName("android","com.android.internal.app.ResolverActivity"));
startActivity(webIntent);
And get the following result:
While this allows to choose the app and has options I need, to set Chrome as a default, the user will first have to click on Chrome, and then get this dialog again to set Chrome as a default (it will appear in place of Firefox).
But what I want to achieve is:
I tried different approaches I could find on SO with no luck. Any suggestions are appreciated.
Upvotes: 1
Views: 1325
Reputation: 1006674
As Mimmo noted, you cannot change the behavior of the system chooser, and the stock Android 5.0+ chooser only allows the user to make the last-visited app the default via "Always". Also, you have no way of setting the default app yourself, for obvious security reasons.
I also strongly recommend you get rid of your setComponent()
call, as that is unlikely to work across all Android devices. Device manufacturers can and do change things like the chooser, which may well involve different classes in different packages.
Upvotes: 1