使用意图发送短信不会在某些设备上添加收件人 [英] Sending SMS using Intent does not add recipients on some devices

查看:150
本文介绍了使用意图发送短信不会在某些设备上添加收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发短信用低于code:

I send SMS using code below:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:" + phoneNumber));
        intent.putExtra("address", phoneNumber);
        intent.putExtra("sms_body", messageBody);
        intent.setType("vnd.android-dir/mms-sms");
        context.startActivity(intent);

我添加了两个乌里与smsto:和地址字符串额外的意图。它适用于大多数设备,但在一些 - 它没有。其中一个设备是SE XPERIA迷你。还有什么发送短信时,要确保收件人可以添加在SMS应用程序设置?

I added both Uri with smsto: and address String extra to Intent. It works on most devices, but on some - it doesn't. One of the devices is SE XPERIA Mini. What else can be added when sending SMS to make sure recipient is set in SMS App?

推荐答案

我看着意图来源,似乎是有意设置类型删除的数据和设定数据删除类型。这是我发现:

I looked into Intent source and it seems that setting intent type removes data and setting data removes type. This is what I've found:

public Intent setData(Uri data) {
        mData = data;
        mType = null;
        return this;
    }

public Intent setType(String type) {
        mData = null;
        mType = type;
        return this;
    }

public Intent setDataAndType(Uri data, String type) {
        mData = data;
        mType = type;
        return this;
    }

所以设置类型将覆盖在Uri.parse规定(smsto:+ phoneNumber的),我的数据。我也尝试使用setDataAndType,但后来只的android无法找到合适的意向,开始为这样的组合......所以这是最终的解决方案:

So setting type overrides my data provided in Uri.parse("smsto:" + phoneNumber). I also tried using setDataAndType, but then android just can't find the right Intent to start for such combination... So this is the final solution:

Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.putExtra("address", phoneNumber);
        intent.putExtra("sms_body", messageBody);
        intent.setData(Uri.parse("smsto:" + phoneNumber));
        context.startActivity(intent);

这似乎工作,在不同的设备有什么我可以测试。我希望这将是任何人谁面临着同样的问题有所帮助。

It seems to work on different devices what I can test on. I hope this will be helpful for anyone who faces the same problem.

干杯!

这篇关于使用意图发送短信不会在某些设备上添加收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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