发送意图当检测到目标应用程序

编程入门 行业动态 更新时间:2024-10-15 14:17:08
本文介绍了发送意图当检测到目标应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我通过发送意图(ACTION_SEND)共享图像。

我想知道,如果任何应用程序中选择了共享或不。我怎样才能做到这一点,我怎么知道,如果像发送成功?

code我已经习惯了分享图片是在这里:

意图份额=新的意图(Intent.ACTION_SEND); share.setType(图像/ *); share.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(新文件(imageSharePath))); startActivity(Intent.createChooser(份额,共享图片));

解决方案

您需要实现自己的对话框对活动的选择。

要创建你需要使用这样的对话 PackageManager.queryIntentActivities()。这个方法返回名单,其中,ResolveInfo>

ResolveInfo 包含有关活动(如 resolveInfo.activityInfo.packageName ),并与帮助的一些信息PackageManager你可以得到其他的信息(用于显示在对话框中的活动) - 应用程序图标绘制,应用标签等

中显示结果列表在对话(或在风格作为对话的活动)。当一个项目被点击创建新的 Intent.ACTION_SEND ,添加你想要的内容,并添加所选活动 intent.setPackage(程序包名称)的封装。

I am sharing image by using the send intent(ACTION_SEND).

I want to know if any application is selected for sharing or not. How can I do that and how do I know if the image was sent successfully?

Code I have used to share image is here :

Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); share.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(imageSharePath))); startActivity(Intent.createChooser(share, "Share Image"));

解决方案

You need to implement your own dialog for the activity selection.

To create such dialogs you need to use PackageManager.queryIntentActivities(). This method returns List<ResolveInfo>.

ResolveInfo contains some information about an activity (e.g. resolveInfo.activityInfo.packageName), and with the help of PackageManager you can get other information (useful for displaying the activity in the dialog) - application icon drawable, application label, etc.

Display the results in a list in a dialog (or in an activity styled as a dialog). When an item is clicked create new Intent.ACTION_SEND, add the content you want and add the package of the selected activity intent.setPackage(pkgName).

更多推荐

发送意图当检测到目标应用程序

本文发布于:2023-07-14 10:09:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   应用程序   检测到   目标

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!