gpt4 book ai didi

android - 是否可以检测 ACTION_SEND Intent 是否成功?

转载 作者:行者123 更新时间:2023-11-29 15:38:14 26 4
gpt4 key购买 nike

我有一个简单的 Android 应用程序,代码如下(来自 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)));

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

最佳答案

Is there a way to read an intent response?

不是来自任意行为的任意 Activity 。

Intent 操作的文档会告诉您是否有预期的输出。因此,例如 ACTION_GET_CONTENT is documented to have output .对于那些 Intent 操作,您使用 startActivityForResult(),部分输出将是一个“结果代码”,让您大致了解结果是什么。

但是:

  • 并非每个 Intent 操作都记录有输出。值得注意的是,ACTION_SEND is not documented to have output .在这种情况下,您不使用 startActivityForResult()(而是使用 startActivity())。即使您确实使用了 startActivityForResult(),您也无法知道负面结果是否意味着用户取消,或者其他 Activity 是否只是遵循文档而没有返回结果。

  • 有些 Activity 存在错误,无法在应有的时候返回结果。

  • 您对成功结果的定义与 Activity 对成功结果的定义可能不同。

关于android - 是否可以检测 ACTION_SEND Intent 是否成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45850756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com