回调的意图选择屏幕自定义项 [英] Callback for Custom Item in Intent Chooser Screen

查看:261
本文介绍了回调的意图选择屏幕自定义项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用例是从意向选配一个自定义的下载选项下载图像。我知道我可以通过添加一些code像下面添加自定义的选项:

 意图份额=新的意图(Intent.ACTION_SEND);
share.setType(text / plain的);
share.putExtra(Intent.EXTRA_TEXT,消息);

意图addIntent =; //任何你想要的

意向选择器=新的意图(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INTENT,股);
chooser.putExtra(Intent.EXTRA_TITLE,标题);

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

我也有到位的功能,将下载的图像我。我的问题是,我可以检测到自定义选项,选择/点击的用户,然后设置一个回调到我的下载功能直接进行下载操作?

注:我不想在此过程中启动任何新的活动。只是在寻找指针就如何我可能设置一个回调在选择器这个自定义选项。

解决方案
  

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

只有在Android 5.1+,如果你使用<一个href="http://developer.android.com/reference/android/content/Intent.html#createChooser%28android.content.Intent,%20java.lang.CharSequence,%20android.content.IntentSender%29"相对=nofollow> 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.

这篇关于回调的意图选择屏幕自定义项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆