我试图获取保存在手机中的消息 ID。但我没能得到它。我现有的代码在这里
@Override
public void onReceive(Context context, Intent intent) {
String address = "";
String message = "";
String msg_id="";
Bundle extras = intent.getExtras();
if (extras != null) {
Object[] smsExtra = (Object[]) extras.get("pdus");
for (int i = 0; i < smsExtra.length; i++) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
message += sms.getMessageBody();
address = sms.getOriginatingAddress();
}
sms = new Sms(msg_id,message, address);
UploadSms up = new UploadSms();
up.start();
Toast.makeText(context,
"SMS Received>>" + message + "From >>" + address,
Toast.LENGTH_LONG).show();
}
}
通过这个我得到短信正文和发件人号码。但我知道 android 手机中的每条消息都有一个唯一的号码,我检索了它。但无法在 onReceive 方法中检索。谢谢