不同 Action 的android sharingIntent

标签 android android-intent share

对于以下 shareIntent:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);         
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "to share this!"));   

应用会弹出有分享功能的应用列表:

我想问一下是否可以按照客户选择的方式进行编码,例如。 whatsapp 或 SMS 它会执行 Action A,但如果客户选择 Facebook,它会执行 Action B?

谢谢!

最佳答案

您正在寻找的是类似于使用 startActivityForResult() 并希望目标应用程序设置结果以便您可以在 中接收有意义的 Intent 数据 >onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data){}

但是;不幸的是,这可靠并且不适用于大多数应用程序。

我已经使用多个应用程序对其进行了测试,包括 SMS、Google+、Facebook、Gmail 和 ColorNote;对于所有这些,我在我的 onActivityResult 中得到 data=nulll 除了 ColorNote 我得到一个有效的 Intent data 的操作类似于 content://note.socialnmobile.provider.colornote/notes/41

所以这真的取决于目标应用程序,据我所知,没有其他可靠的方法可以让您的应用程序知道用户选择了哪个应用程序来共享数据。

关于不同 Action 的android sharingIntent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14899961/

相关文章:

android - 在应用程序之间使用隐式 Intent 的自定义操作

android - 带线条滚动的 TextView

android - 斯卡拉+安卓 : Is anybody successfully building and debugging in Eclipse?

android - 从另一个 Activity 启用按钮

Android:共享 CSV 文件

ios - 如何共享开发中的应用程序的当前状态

Android 共享 Intent EXTRA_STREAM

java - Android fragment 事务动画在 View 寻呼机上不起作用

android - Delphi Android App 在键盘连接/断开时崩溃

android - 使用 FLAG_ACTIVITY_REORDER_TO_FRONT 时 overridePendingTransition 不起作用