发送同样的两次短信 [英] Sending the same SMS twice

查看:127
本文介绍了发送同样的两次短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让短信Android应用程序,但我发现,我以前从未见过,甚至在谷歌我还没有发现这样的事情的错误。
所以,如果你能帮助我...我会很高兴。

I'm trying to make an sms android app, but i'm getting an error that i've never seen before, even in google i haven't found anything like that. So, if you could help me... i'll be glad

有关某些原因,该程序在同一时间发送两个消息(同一SMS)。
但它只是发生在生产。当我使用模拟器,一切工作正常!它发送短信只有一次......

For some reason, the program is sending two messages (the same sms) at the same time. But it just happens in production. When i'm using the simulator, everything works fine! it Sends the sms just once ...

我试过很多电话,很多电话运营商,但错误总是会发生的。
我真的不知道该怎么去发现正在发生的事情,因为它只会发生在真正的手机,而不是在模拟器...

I've tried many phones and many phone operators but the error always happens. I really dont know how to discover what is happening because it happens only in real phones and not in simulator...

下面的 code如下:

private void sendSMS(String phoneNumber, String message, Context context) {
    ContextWrapper cw = new ContextWrapper(context);
    Context baseContext = cw.getBaseContext();

    Intent intentSMS = new Intent(baseContext, SMSManagerService.class);
    intentSMS.putExtra("celNumber", phoneNumber);
    intentSMS.putExtra("textMessage", message);

    Random s = new Random(System.currentTimeMillis());
    PendingIntent pendingIntent = PendingIntent.getService(cw, s.nextInt(), intentSMS, PendingIntent.FLAG_ONE_SHOT);
    try {
        pendingIntent.send();
    } catch (CanceledException e) {
    }
}

SMSManagerService.class

SMSManagerService.class

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Bundle intentExtras = intent.getExtras();
    if (intentExtras != null) {
        String phoneNumber = intentExtras.getString("celNumber");
        String message = intentExtras.getString("textMessage");

        if (isContentValid(phoneNumber, message)) {
            sendSMS(phoneNumber, message);
        }
    }

    return super.onStartCommand(intent, flags, startId);
}

 private void sendSMS(String phoneNumber, String message) {
    sentPI = registerSMSSent(phoneNumber, message);
    deliveredPI = registerSMSdelivered();

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}

所以..任何人......任何暗示?!

so.. anyone... any hint?!

THX

推荐答案

只是为了澄清这个问题,并给出答案...

Only to clarify the question and give an answer...

这是Android上的一个bug,这取决于手机和Android版本,正在运行SMS应用。

It's a bug on android, depending on phone and android version, that is running the sms application.

该错误是此相关:
谷歌code的Andr​​oid inssues

和一个可能,这就是对我的作品,在这里相关:
<一href=\"http://stackoverflow.com/questions/9706039/android-sendtextmessage-sends-two-identical-messages-on-exceution-how-to-fix\">Android sendTextMessage上exceution发送两个相同的消息,如何解决?

and one possible, thats works for me, is related here: Android sendTextMessage sends two identical messages on exceution, how to fix?

这篇关于发送同样的两次短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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