2

Objective: I want to open an intent chooser to show only the native Camera app and the native Gallery app.

What I have right now: I have the native Camera app, native Gallery app and all other apps that can open files(Astros File Manager, Photos app... etc)

So, is there anything I am missing? such that it would help limit my intent chooser to only show only the apps I need? (Gallery and Camera only)?

Thanks, for reading and would appreciate any comments or suggestions.

        Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT,null);
        galleryIntent.setType("image/*");
        galleryIntent.setClassName("com.google.android.gallery3d", "com.android.gallery3d.app.Gallery");

        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        Intent chooser = new Intent(Intent.ACTION_CHOOSER);
        chooser.putExtra(Intent.EXTRA_INTENT, galleryIntent);
        chooser.putExtra(Intent.EXTRA_TITLE, "Select a Photo");
        Intent[] intentArray =  {cameraIntent};
        chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
        startActivityForResult(chooser,CAMERA_CODE);
xiaowoo
  • 2,248
  • 7
  • 34
  • 45
  • 1
    Don't think you can achieve this any way except hardcoding packages of apps that need to be shown in your chooser. But these packages may vary in different systems - I mean default gallery apps won't have same packages in raw Android & Cyanogenmod, for example. So better leave all apps to user's choice – Sam Feb 12 '14 at 21:38
  • @SamN-a I hardcoded the name of the gallery Intent, but its still showing all the apps(gallery, photos, astro..etc). – xiaowoo Feb 12 '14 at 21:47
  • 1
    Please allow the user to use whatever apps the user wants. If the user hates their default camera app and wishes to use any of the available third-party ones, that is the user's choice, not yours. If the user wants to use a gallery-style app that integrates with their preferred social network, that is the user's choice, not yours. You are not more important than your users. – CommonsWare Feb 12 '14 at 22:13

1 Answers1

1

As @SamN-a writes, it's not generally possible. Using hardcoded class names is not a good practice: these are not guaranteed to be present on all devices, even if you only look at devices with standard GAPPS installed.

But it is good practice to show a custom chooser instead of the system default, and provide the most relevant (e.g. last used) choice on click away, straight on the Action Bar.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I've mentioned that there're lots of problems in using hardcoded packages. Could you provide some code samples for custom chooser? – Sam Feb 12 '14 at 22:13
  • 1
    @SamN-a: have a look at http://stackoverflow.com/questions/5734678/custom-filtering-of-intent-chooser-based-on-installed-android-package-name and references thereof. – Alex Cohn Feb 12 '14 at 22:35