Callback for Custom Item in Intent Chooser Screen

醉酒当歌 提交于 2020-04-07 05:43:39

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/32749856/callback-for-custom-item-in-intent-chooser-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!