短信发送消息与电话号码

时间:2014-04-21 06:55:24

标签: android broadcastreceiver smsmanager

我试图发送群组短信,但它运行正常。但是,我想知道哪些号码是我的短信发送状态:

对于已知交付状态,我使用下面的代码:

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

        }

    }

目前短信已发送消息显示正常。但是,在这里我想显示交付目标的移动电话号码。如何使用广播接收器获取目标手机号码?

任何想法??

提前致谢..

1 个答案:

答案 0 :(得分:4)

您可以使用收件人的号码附加一个额外的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");