当我收到通知消息“abc”时,我想打开我的应用程序。我可以用 SMSReceiver 做到这一点,但只能收到短信。我想做这个whatsapp消息。抱歉英语不好。
@Override
public void onReceive(Context context, Intent intent) {
String hangiNumaradan = "";
String neYazmis = "";
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
if (bundle != null) {
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]);
hangiNumaradan += msgs[i].getOriginatingAddress();
neYazmis += msgs[i].getMessageBody().toString();
}
Toast.makeText(context, hangiNumaradan + " gelen mesaj " + neYazmis, Toast.LENGTH_LONG).show();
}
}
此代码是 smsreceiver 和 toast 消息。