2

My use case is to download an image from a Custom Download option from Intent Chooser. I understand that I can add the custom option by adding some code like below :

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");       
share.putExtra(Intent.EXTRA_TEXT, message);

Intent addIntent = ;//whatever you want

Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INTENT, share );      
chooser.putExtra(Intent.EXTRA_TITLE, "title");

Intent[] intentArray =  {addIntent }; 
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivity(chooser);

I also have the the function in place which will download the image for me. My question is, Can I detect that the custom option was selected/clicked by the user and then set a callback to my download function directly and proceed with the download operation ?

Note : I do not want to launch any new activity during the process. Just looking for pointers on how I could possibly set a call back for this custom option in the chooser.

Abhishek Sabbarwal
  • 3,758
  • 1
  • 26
  • 41

1 Answers1

4

Can I detect that the custom option was selected/clicked by the user and then set a callback to my download function directly and proceed with the download operation ?

Only on Android 5.1+, if you use the three-parameter flavor of createChooser(), where you can supply an IntentSender that is notified about the choice... and then only if by "set a callback to my download function directly and proceed with the download operation" you mean "launch an activity that does the download".

Otherwise, you would need to roll your own chooser-style UI, then use the user's choice to craft an explicit Intent to route the user to the requested activity.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you very much. That helps a lot. I guess I would go and roll my own Custom-style chooser. I will accept this answer in a couple of minutes. – Abhishek Sabbarwal Sep 23 '15 at 21:42