是否可以检测到是否有ACTION_SEND目的? [英] Is it possible to detect if an ACTION_SEND Intent suceeded?

查看:51
本文介绍了是否可以检测到是否有ACTION_SEND目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Android应用,其代码如下(来自 Android文档):

  Intent sendIntent = new Intent();sendIntent.setAction(Intent.ACTION_SEND);sendIntent.putExtra(Intent.EXTRA_TEXT,这是我要发送的文本.");sendIntent.setType("text/plain");startActivity(Intent.createChooser(sendIntent,getResources().getText(R.string.send_to)));; 

但是我找不到一种方法来检测电子邮件是否已成功发送(或用户取消了).有没有办法阅读意向响应?

解决方案

是否可以读取意图回复?

不是来自任意活动的任意动作.

Intent 操作的文档将告诉您是否有预期的输出.因此,例如,据记录 ACTION_GET_CONTENT 输出.对于那些 Intent 操作,您可以使用 startActivityForResult(),并且输出的一部分将是一个结果代码",以使您大致了解结果是什么.>

但是:

  • 并非每个 Intent 操作都被记录为具有输出.值得注意的是,未记录 ACTION_SEND 具有输出.在这种情况下,您无需使用 startActivityForResult()(而是使用 startActivity()).即使您确实使用 startActivityForResult(),您也无法知道否定结果是否意味着用户已取消,或者其他活动是否只是在遵循文档并且没有返回结果.

  • 某些活动存在错误,应有的情况下无法返回结果.

  • 您对成功结果的定义和活动对成功结果的定义可能会有所不同.

I have a simple Android app with code like this (from the Android Documentation):

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));

But I can't find a way to detect of the email was successfully sent (or the user cancels out). Is there a way to read an intent response?

解决方案

Is there a way to read an intent response?

Not from an arbitrary activity for an arbitrary action.

The documentation for Intent actions will tell you if there is expected output or not. So, for example, ACTION_GET_CONTENT is documented to have output. For those Intent actions, you use startActivityForResult(), and part of the output will be a "result code" to let you know generally what the result was.

However:

  • Not every Intent action is documented to have output. Notably, ACTION_SEND is not documented to have output. In that case, you don't use startActivityForResult() (but instead use startActivity()). Even if you do use startActivityForResult(), you have no way to know if a negative outcome means that the user cancelled out or if the other activity simply is following the documentation and did not return a result.

  • Some activities are buggy and fail to return results when they should.

  • Your definition of a successful result and the activity's definition of a successful result may differ.

这篇关于是否可以检测到是否有ACTION_SEND目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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