自动侦听包含某些密码的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();
}
}
}
答案 0 :(得分:0)
您需要在清单中指定权限:
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>