【问题标题】:sms delivery message with phone number带有电话号码的短信发送消息
【发布时间】:2014-04-21 16:06:37
【问题描述】:

我尝试发送群组短信,它工作正常。但是,我想知道我收到了哪些关于已发送状态的短信:

为了了解交付状态,我使用了以下代码:

public class SMSdelivered extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub

            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(context, "SMS DELIVERED", Toast.LENGTH_SHORT).show();
               //want to display mobile number tooo
                break;
            case Activity.RESULT_CANCELED:
                Toast.makeText(context, "SMS NoT DELIVERED", Toast.LENGTH_SHORT)
                        .show();
                break;
            }

        }

    }

目前SMS DELIVERED消息显示正常。但是,这里我想显示已交付目标的手机号码。如何使用广播接收器获取传递的目标手机号码?

有什么想法吗??

提前谢谢..

【问题讨论】:

    标签: android broadcastreceiver smsmanager


    【解决方案1】:

    您可以在Intent 上附加一个额外的内容,用于使用收件人的号码创建已交付的PendingIntent,然后在您的BroadcastReceiver 中检索它。

    Intent delivered = new Intent(ACTION_SMS_DELIVERED);
    delivered.putExtra("addressee", number);
    PendingIntent pendingDelivered = PendingIntent.getBroadcast(context, 0, delivered, 0);
    

    onReceive():

    String number = intent.getStringExtra("addressee");
    

    【讨论】:

    • 感谢您的回复,我已经尝试过了,但是,intent.getStringExtra 返回空值..
    • PendingIntents 可以重复使用。尝试使用PendingIntent.FLAG_UPDATE_CURRENTPendingIntent.FLAG_CANCEL_CURRENT 作为最后一个参数调用getBroadcast()
    猜你喜欢
    • 2023-04-02
    • 2013-12-04
    • 2016-04-15
    • 2015-01-04
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多