I am using Android's default share intent to share an image to other apps. But I would like to add an option like Save to Gallery
which saves that Image directly to Gallery in media or images or my app's folder.
Currently I am using the simple code to share image:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, "Share to"));
When I tried WhatsApp's share button from profile picture, there is an option of "Save To Gallery
" Option. Now, I came to know that, it is not pre-build in android. That is the manual action added by WhatsApp which somehow saves an image to specific path. On Long pressing that "Save to gallery
" button shows that, that action is of WhatsApp's app. So that means WhatsApp has written some logic for it. It is the same default ACTION_SEND
intent with image/*
mime type with an additional custom action "Save to Gallery
".
That's totally fine. I want to add that kind of logic for my app, too. I can register <intent-filter>
which can handle this action but it will globally accept any image from any app to save to gallery.
How can I add a manual action for my sharing Intent or <intent-filter>
activity which can be specific to my app only (visible by my app only) and serves the purpose of saving an Image to Gallery?
The following snippet does the following: At first we are querying the system for IntentActivities, which can handle our Share-Intent. After that we build a List of LabeledIntents. Finally we add our custom share action to this list and we will present the list to the user, with the default chooser dialog.