如何设置关键字以从短信中启动广播接收器?我的广播接收器正常工作,问题是它在接收任何短信时开始活动,我只需要它开始接收 1 或 2 个关键字“酒店和/或房屋”我该怎么做......谢谢。下面是我的代码
-显现- ” ”
-实际接收器类-公共类 SMSReceiver 扩展 BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
//show first message
Toast toast = Toast.makeText(context, "Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
toast.show();
//and then start an activity
Intent i = new Intent(context,AppActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);