1
這裏檢索一個SMS是我使用檢索輸入接收到的SMS!:短信代碼在服務類
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
String strd = "";
String strm = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
//if(msgs[i].getOriginatingAddress().equals("9819861968")) {
//---get the sender address/phone number---
str += msgs[i].getOriginatingAddress();
str +=":\n";
strd += msgs[i].getOriginatingAddress();
strd +=":\n";
// }
//---get the message body---
str += msgs[i].getMessageBody().toString();
strm += msgs[i].getMessageBody().toString();
// this.abortBroadcast();
}
現在我想獲得短信和號碼。 請幫我
好的。我正在測試 – prince47
我是初學者,可以給我發送從BroadcastReceiver類到服務類的參數的說明,因爲刪除this.abortBroadcast();沒有給 以及在BroadcastReceiver之前運行服務的事實不成問題?案例我甚至試圖保持SMS從BroadcastReceiver的SharedPreferences和檢索服務類,但它首先運行服務 請幫我我被解僱了一週 – prince47
更新了我的答案。 –