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

本文是小编为大家收集整理的关于无法使用SmsManager在某些Android手机上发送短信的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我的移动应用程序偶尔正在发送短信,一切都在大多数手机上工作,但我开始收到来自一些用户的电子邮件,说明消息不会出现.这是我使用的代码:

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

我已经阅读了我应该使用的某个地方,所以我尝试如下:

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,Samsung Sidekick手机.

请记住它不是特定于手机,我已经在其中两部手机(我的朋友)上测试了该应用程序,并且文本消息正常发送

推荐答案

这里的问题是根本没有处理重试.短信可以通过各种丰富多彩的方式发送.您可以使用Sent PendingIntent使用类似的东西倾听这些事件:

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
    }
}

我怀疑发生了什么是用户在发送消息时没有信号,所以它失败,永远不会重试.这也可以解释为什么它不是设备特定的.

本文地址:https://www.itbaoku.cn/post/102355.html

问题描述

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);

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);   

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

Please keep in mind it's not phone specific, i have tested the app on two of these phones (my friends) and the text message was sent normally

推荐答案

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.