广播接收器为多个发送的消息? [英] BroadCastReceiver for Multiple sent Messages?

查看:173
本文介绍了广播接收器为多个发送的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序我在一次工作这完全正常发送多个短信。但是,当我试图接收广播接收器确认消息我期待得到所有的数字,但我在n个数接受同样的一个号码,而不是结束。

In my app i am sending multiple sms at one time which working perfectly fine. But when i am trying to receive confirmation messages in Broadcast Receiver i am expecting to get all numbers but i end up in receiving same one number instead of n numbers.

要发送短信

Intent intent = new Intent(SENT);
intent.putExtra("phonenumber", sms_phonenumber);
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
SmsManager sms_man = SmsManager.getDefault();
sms_man.sendTextMessage(sms_phonenumber, null, sms_message, sentPI, null);

要接收发送确认

private class SMSReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context arg0, Intent intent) {

        switch (getResultCode()) {
        case Activity.RESULT_OK: 
            String phoneNumber = intent.getExtras()
                    .getString("phonenumber");

            alertMessage("Request sent to " + phoneNumber + ".");

            break;

        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
            String phoneNumber1 = intent.getExtras().getString(
                    "phonenumber");

            alertMessage("Sending Failed to " + phoneNumber1 + ".");

            break;

        case SmsManager.RESULT_ERROR_NO_SERVICE:
            String phone = intent.getExtras().getString(
                    "phonenumber");

            alertMessage("No service");

            break;

        case SmsManager.RESULT_ERROR_NULL_PDU:
            alertMessage("Null PDU");
            Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT)
                    .show();
            break;

        case SmsManager.RESULT_ERROR_RADIO_OFF:
            alertMessage("Radio off");
            break;
        }
    }
}

我搜索了很多谷歌和SO但他们没有解决我的问题。

I am searched a lot in Google and SO but none of them solves my issue.

感谢您的帮助。

推荐答案

尝试意向之前的所有时间,具有唯一的ID为集挂起意图

Try to Pending intent with all time with Unique id for Set Pending intent

的PendingIntent的PendingIntent = PendingIntent.getService(这一点,UID,mIntent,PendingIntent.FLAG_ONE_SHOT);

PendingIntent pendingintent = PendingIntent.getService(this, uId, mIntent, PendingIntent.FLAG_ONE_SHOT);

这篇关于广播接收器为多个发送的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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