嗨,我有以下广播接收器,因此当我收到短信时会告知我的活动。我唯一不知道的是如何获取新短信的 id。如何才能做到这一点?我知道如何获取电话号码和消息,但我不需要我需要它的 id 任何帮助将不胜感激
BroadcastReceiver sentSmsBroadcast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == SMS_RECEIVED) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[])bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
}
if (messages.length > -1) {
//Get sms id
}
}
}
}
};
IntentFilter filterSend = new IntentFilter();
filterSend.addAction("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sentSmsBroadcast, filterSend);