0
SMSReceiver.java收到ListView項短信使用意向
public class SMSReceiver extends BroadcastReceiver{ public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); String str = ""; if (bundle != null) { Object [] pdus = (Object[])bundle.get("pdus"); SmsMessage [] msgs = new SmsMessage[pdus.length]; String [] lmsg = new String[2048]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage .createFromPdu((byte[]) pdus[i]); str += msgs[i].getOriginatingAddress() + "\n " + msgs[i].getMessageBody().toString() +"\n"; } for (int j = 0; j < lmsg.length ; j++) { lmsg[j] = str; } Toast.makeText(context, str, Toast.LENGTH_LONG).show(); } } }
2.RedirectActivity
public class RedirectActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
intent.setClass(RedirectActivity.this, ParentActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
}
我想從SMS資料ParentActivity。
- SMSReceiver:接收短信
- RedirectActivity:將消息傳遞給ParentActivity
- ParentActivity:由意向
從redirectActivity獲取數據,我SMSReceiver和RedirectActivity之間有問題。它不起作用。
的[服務追趕短信詳情]可能的複製(http://stackoverflow.com/questions/43996446/catching-sms-details-in-service) – jagapathi
@Hhhh請檢查我的答案.. –