SMS を受信すると、別のアクティビティを開始できます。私が知りたいのは、テキスト メッセージをリソース (xml 文字列) のコンテンツと比較する方法、および textview、 editText を比較する方法です。ブロードキャスト レシーバー クラスで textview と edittext 値から参照を取得することは可能ですか? 以下は、値を比較せずにアクティビティを開始するコードです。
public class SMSReceiver は BroadcastReceiver を拡張します {
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
String phonenumber = "";
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]);
phonenumber=msgs[i].getOriginatingAddress();
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//=======launch the ShowMap1 when recieve SMS==============//
Intent mainActivityIntent = new Intent(context, ShowMap2.class);
mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mainActivityIntent.putExtra("phn", phonenumber);
mainActivityIntent.putExtra("sms", str);
context.startActivity(mainActivityIntent);
//========================END=============================//
}
}
}