StartActivityForResults总是返回RESULT_CANCELLED的Intent.ACTION_SEND [英] StartActivityForResults always returns RESULT_CANCELLED for Intent.ACTION_SEND

查看:248
本文介绍了StartActivityForResults总是返回RESULT_CANCELLED的Intent.ACTION_SEND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于共享弹出时,我分享成功的WhatsApp的内容,但仍返回RESULT_CANCELLED。同样的结果,当我发送使用Gmail电子邮件。

调用共享的意图, ACTION_SEND startActivityForResult 总是返回已取消

 意图sharingIntent =新的意图(Intent.ACTION_SEND);
    sharingIntent.setType(text / plain的);
    sharingIntent.putExtra(android.content.Intent.EXTRA_TITLE,Taxeeta,驾驶室围绕遏制);
    sharingIntent
        .putExtra(
            android.content.Intent.EXTRA_TEXT,
                雇用了一辆出租车不再需要你去伺候呼叫中心,或支付
                +方便(是正确的!)负责。Taxeeta接你
                +司机直接,一个快速的书的经验,随着Taxeeta
                +你可以把问题在你自己的手中(直译)。下载
                +的应用程序,为您的手机访问http://www.taxeeta.com);
    startActivityForResult(Intent.createChooser(sharingIntent,股份,赚取额外的特权),111);
 

ActivityForResult code

  @覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
    如果(要求code == 111){
        如果(结果code == RESULT_OK){
            Toast.makeText(这一点,好DUDE,Toast.LENGTH_LONG).show();
        }否则,如果(结果code == RESULT_CANCELED){
            Toast.makeText(这一点,Oversmart嗯!,Toast.LENGTH_LONG).show();
        }
    }
}
 

解决方案

startActivityForResult()只适用于那些打算叫这样的活动。如果您呼叫的活动没有明确返回一个结果,你会得到RESULT_CANCELED默认结果。显然 ACTION_SEND 没有设计被称为这种方式。该<一href="http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND">documentation为 ACTION_SEND 表示是没有输出。(即:不产生结果)

见<一href="http://developer.android.com/reference/android/app/Activity.html#startActivityForResult%28android.content.Intent,%20int,%20android.os.Bundle%29">documentation为 Activity.startActivityForResult()

  

请注意,此方法只应与意向协议使用的   被定义为返回一个结果。在其它协议(如   ACTION_MAIN或ACTION_VIEW),你可能不会当你得到的结果   期望。例如,如果你正在开展活动使用的   singleTask启动模式,它不会在你的任务运行,因此你会   立即收到取消的结果。

As the share pop up appears, I shared the content on WhatsApp successfully, but still returns RESULT_CANCELLED. Same result when I send a email using Gmail.

Calling Sharing intent, ACTION_SEND with startActivityForResult always returns 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 Code

@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() only works with activities that are intended to be called that way. If the activity you are calling doesn't explicitly return a result, you will get the default result RESULT_CANCELED. Obviously ACTION_SEND is not designed to be called this way. The documentation for ACTION_SEND indicates that is generates no output (ie: generates no result).

See the documentation for 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.

这篇关于StartActivityForResults总是返回RESULT_CANCELLED的Intent.ACTION_SEND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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