自動偵聽包含某些密碼的SMS消息的應用程序。一旦接收到該消息,您可以撥打自動接收短信的號碼。每當我發送消息撥號它什麼都不做。即使麪包沒有顯示。使用SMS接收器
public class Receiving extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SmsMessage[] sms = null;
Bundle bundle = Intent.getExtras();
String str = " SMS From : ";
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
sms = new SmsMessage[pdus.length];
for (int i = 0; i < sms.length; i++) {
sms[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (i == 0) {
str += sms[i].getOriginatingAddress();
str += ":";
}
str += sms[i].getMessageBody().toString();
if (sms[i].getMessageBody().equals("Dial")) {
Intent in = new Intent(Intent.ACTION_DIAL);
in.setData(Uri.parse("tel:"+ sms[i].getOriginatingAddress()));
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in2); }
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
}
你用什麼意圖過濾器? –
AndroidManifest.xml <類別機器人:名稱= 」android.intent.category.LAUNCHER「/> 意圖濾波器> <接收機機器人:名稱=」 com.example.sms.Receiving 「> <意圖濾波器> <操作機器人:名稱=」 android.provider.Telephony.SMS_RECEIVED「/> 意圖濾波器> '@JakubSzczygieł –
Disguise