gpt4 book ai didi

android - StartActivityForResult 始终为 Intent.ACTION_SEND 返回 RESULT_CANCELED

转载 作者:可可西里 更新时间:2023-11-01 18:51:10 25 4
gpt4 key购买 nike

当出现分享弹窗时,我在 WhatsApp 上分享内容成功,但仍然返回 RESULT_CANCELLED。当我使用 Gmail 发送电子邮件时,结果相同。

使用 startActivityForResult 调用共享 Intent ,ACTION_SEND 总是返回 CANCELLED

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TITLE, "Taxeeta, Cab Around The Curb");
sharingIntent
.putExtra(
android.content.Intent.EXTRA_TEXT,
"Hiring a cab no longer needs you to wait on call centers, or pay a"
+ " convenience (yeah right!!) charge. Taxeeta connects you"
+ " to drivers directly, for a quick book experience. With Taxeeta"
+ " you can take matters in your own hands (literally). To download"
+ " the app for your phone visit http://www.taxeeta.com");
startActivityForResult(Intent.createChooser(sharingIntent, "Share and earn a extra Priviledge"), 111);

ActivityForResult 代码

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 111) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Ok DUDE", Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Oversmart Eh!!", Toast.LENGTH_LONG).show();
}
}
}

最佳答案

startActivityForResult() 仅适用于旨在以这种方式调用的 Activity 。如果您调用的 Activity 没有明确返回结果,您将获得默认结果 RESULT_CANCELED。显然 ACTION_SEND 并不是设计成这样调用的。 documentation ACTION_SEND 表示不生成输出(即:不生成结果)。

参见 documentation对于 Activity.startActivityForResult():

Note that this method should only be used with Intent protocols that are defined to return a result. In other protocols (such as ACTION_MAIN or ACTION_VIEW), you may not get the result when you expect. For example, if the activity you are launching uses the singleTask launch mode, it will not run in your task and thus you will immediately receive a cancel result.

关于android - StartActivityForResult 始终为 Intent.ACTION_SEND 返回 RESULT_CANCELED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16622012/

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