It is not possible to do startActivity () with a Chooser requesting only once per application.

When you make startActivity() using chooser, Android will present a list of all applications that have the right to process your Intent , as well as parameters to set this assignment both permanently and once (on the ICS there is a button "Always" and "Only once" , at 2.x this is a check box). 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 don’t see the "Always only once" buttons and cannot make my choice permanent (I only got a list of applications and can launch them by clicking on it). What elementary I overlooked that Android could not make the user's choice permanent?

Take a look at the photos: the left dialog is what I would like to see, but really is what I get now (a different number of applications in both dialogs does not matter):

enter image description here

+8
android android-intent
source share
1 answer

For the record - it was a too interpreted type of error (mine). The choice I used is exactly what you can see in the image on the right side. And it constantly appeared because ... I called all the time. I incorrectly assumed that chooser offers Always Always Only Once functionality and will not be displayed if the user tapped Always (and will be displayed if he used Just Once). But this is wrong. Chooser will always be displayed because its role is to let the user select. The Always and Only Once functionality is a great feature of the Android framework for calls to startActivity() and startActivityForResult() and will be displayed automatically when necessary - if there is more than one application (or, more precisely, more than one intent-filter matching) that can handle certain intentions. It will not be displayed if you only have one (or a user who previously tapped Always). You, as a developer, should not care.

So, to fix this, I just changed the viewInExternalApplication() code to just call startActivity() :

 try { context.startActivity( intent ); } catch (.... ) 

and the rest of the structure is.

+16
source share

All Articles