Is it possible to add a custom option(For eg. Download Image) with other share option(shown in attached image) in intent chooser?
Asked
Active
Viewed 1,344 times
0
-
https://developer.android.com/training/building-content-sharing.html – ashkhn Jul 03 '17 at 10:03
-
@akash93 thanks for sharing link but this did not help me. Please suggest something else. – Sapna Sharma Jul 03 '17 at 11:27
-
Have you gone through the link? It contains ( more specifically [this](https://developer.android.com/training/sharing/receive.html) ) exactly what you need – ashkhn Jul 03 '17 at 15:04
-
@akash93 This does not help. We need to have a Download option in Intent chooser – Adnan Jul 04 '17 at 05:07
-
You haven't gone through the link then.. When you register your application using an `intent-filter` and `image` mime-type the callback your app receives contains the image Uri which can be used to access the file. This is **clearly explained** in the documentation link I posted earlier.. – ashkhn Jul 04 '17 at 15:19
2 Answers
2
Unfortunately, I did not get useful answers. I did a workaround to solve this.
Here is the code to add a custom 'Save to Gallery" option(shown in attached image)
Intent downloadIntent = new Intent(aContext, DownloadActivity.class);
downloadIntent.putExtra("url", url);
intentList.add(new LabeledIntent(downloadIntent, "com.don.offers", "Save To Gallery", R.drawable.ic_save_to_gallery));
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
Here DownloadActivity is transparent activity that has the code to download image.
public class DownloadActivity extends AppCompatActivity {
String imageUrl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download);
imageUrl = getIntent().getStringExtra("url");
saveToGallery();
finish();
}
public void saveToGallery() {
try {
String DIR_NAME = "Don Downloaded Images";
String filename = "DON_IMG_" + System.currentTimeMillis();
//String downloadUrlOfImage = "http://fun.localdon.com/DonUGCImg/DON_memes14908366211071492831321991.png";
String downloadUrlOfImage = imageUrl;
File direct =
new File(Environment
.getExternalStoragePublicDirectory(String.valueOf(Environment.DIRECTORY_PICTURES))
.getAbsolutePath() + "/" + DIR_NAME + "/");
if (!direct.exists()) {
direct.mkdir();
Log.e("saveToGallery", "dir created for first time");
}
DownloadManager dm = (DownloadManager) DownloadActivity.this.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(downloadUrlOfImage);
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle(filename)
.setMimeType("image/jpeg")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(String.valueOf(Environment.DIRECTORY_PICTURES),
File.separator + DIR_NAME + File.separator + filename);
dm.enqueue(request);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
final Uri contentUri = Uri.fromFile(direct);
scanIntent.setData(contentUri);
DownloadActivity.this.sendBroadcast(scanIntent);
} else {
final Intent intent1 = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()));
DownloadActivity.this.sendBroadcast(intent1);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
If anyone has better approach please share.Thanks

Vishal Yadav
- 3,642
- 3
- 25
- 42

Sapna Sharma
- 460
- 7
- 22
-
-
@Adnan I did not post whole code, if you need it I will do. intentList is array list to which filtered packages to show in intent chooser added. – Sapna Sharma Jul 07 '17 at 12:34
-
Sapna: Alright Kindly post the entire code here or share it on my email shoutadnan@gmail.com – Adnan Jul 10 '17 at 06:13
-1
Refer this answer: Link
Sample Code:
Github Project

Adnan
- 1,440
- 2
- 18
- 38
-
@SapnaSharma I didn't try personally. But what is the issue you're facing? – Adnan Jul 04 '17 at 07:21