且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

回调的意图选择屏幕自定义项

更新时间:2023-11-14 15:53:52

  

我能察觉的自定义选项,选择/点击的用户,然后设置一个回调到我的下载功能直接进行下载操作?

只有在Android 5.1+,如果你使用 createChooser() ,在那里你可以提供一个 IntentSender 的通知有关的选择.​​.....而且只有通过设置回调到我的下载功能直接进行下载操作你的意思是启动,做下载的活动。

否则,您将需要推出自己的选择器风格的用户界面,然后使用用户的选择,以便起草一个明确的意图,以便将用户请求的活动。

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.

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.