如何确认Android Share Intent是否成功或完成 [英] How to confirm Android Share Intent is successful or complete

查看:545
本文介绍了如何确认Android Share Intent是否成功或完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法确认Android中的Share意图是成功还是不成功? (例如,如果我分享一个Facebook的帖子,我想知道是否成功发布或知道是否被取消。)



以下是Android的意图我用来分享的代码。目前,它启动一个对话框,允许用户选择要分享的应用程序:

  Intent shareIntent = new Intent(android。 content.Intent.ACTION_SEND); 
shareIntent.setType(text / plain);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,body);
activity.startActivity(Intent.createChooser(shareIntent,title));


解决方案

个人而言,我即将说use startActivityForResult(),然后检查返回的内容。但是,您可以在这里阅读更多,这不是那么简单。如果用户取消了意图,则返回相同的号码,就像意图已完成(对于大多数应用程序)。



最终,目前为止,更简单的Share意图一般,您无法检查是否成功。


Is there a way to confirm if a Share intent in Android was successful or unsuccessful? (For example, if I share a Facebook post, I'd like to know if it was successfully posted or know if it was cancelled.)

Below is the Android intent code that I use to Share. Currently, it launches a dialog to allow the user to choose which app to share to:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);    
activity.startActivity(Intent.createChooser(shareIntent, title));

解决方案

Personally, I was about to say "use startActivityForResult()" and check what gets returned. However, as you can read more here, it's not as simple as that. If the intent is cancelled by the user, the same number is returned as if the intent was completed (for most appications).

Ultimately, at the moment for a simpler Share intent in general, you cannot check if it's successful or not.

这篇关于如何确认Android Share Intent是否成功或完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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