无法使用SmsManager的一些Android手机发短信 [英] Unable to send text messages on some Android Phones using SmsManager

查看:259
本文介绍了无法使用SmsManager的一些Android手机发短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的移动应用程序偶尔会发送短信,一切都很正常大多数手机上,但我开始收到一些用户指出消息的电子邮件都不会出来。这里是code我使用:

My mobile app occasionally is sending text messages, everything works great on most phones but i am starting to receive emails from some users stating the messages aren't going out. Here is the code i am using:

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("+12223334444", null, "test sms", null, null);

我曾经读过我应该用PendingIntent,所以我试了一下,如下所示:

I've read somewhere that I should use the PendingIntent, so i tried it as follows:

PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_SENT"), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_DELIVERED"), 0);                     
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(number, null, message, sentPI, deliveredPI);   

到目前为止,我已经得到了三星的Galaxy S II,Sprint公司的Evo Shift键的用户的电子邮件,三星的Sidekick手机。

So far I have gotten emails from users of Samsung Galaxy S II, Sprint Evo Shift, Samsung Sidekick phones.

请记住,这不是手机的具体,我已经测试了其中的两个手机(我的朋友)的应用程序和文本消息通常发送

推荐答案

这里的问题是,你不处理重试的。这是可能的短信无法发送的各种丰富多彩的方式。您可以监听这些事件通过发送 PendingIntent 使用类似:

The problem here is that you aren't handling retries at all. It is possible for the SMS to fail to send in a variety of colourful ways. You can listen for these events using the sent PendingIntent using something like:

public void onReceive(Context context, Intent intent) {
    if (getResultCode() != Activity.RESULT_OK) {
        // failed to send the sms, see SmsManager.ERROR_<description> for more info on why
    }
}

我的怀疑正在发生的事情是,用户可以在发送邮件的时间没有信号,所以它失败,从不重试。这也可以解释为什么它不是特定设备。

What I suspect is happening is that users have no signal at the time you send the message, so it fails and never retries. This would also explain why it isn't device specific.

这篇关于无法使用SmsManager的一些Android手机发短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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