我通过发送意图(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).
更多推荐
发送意图当检测到目标应用程序
发布评论