标签:android 手机管家
这里创建一个短信广播接受者,并让他的优先级最大,设置他的动作为:接收短信(需要添加权限)
<receiver android:name="com.ustc.mobilemanager.receiver.SMSReceiver" > <intent-filter android:priority="1000"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
package com.ustc.mobilemanager.receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.telephony.SmsMessage; import android.util.Log; public class SMSReceiver extends BroadcastReceiver { private static final String TAG = "SMSReceiver"; @Override public void onReceive(Context context, Intent intent) { //写接受短信的代码 Object[] objs = (Object[]) intent.getExtras().get("pdus"); for (Object b : objs) { //具体的某一条短信 SmsMessage sms = SmsMessage.createFromPdu((byte[]) b); //发送者 String sender = sms.getOriginatingAddress(); //短信内容 String body = sms.getMessageBody(); if ("#*location*#".equals(body)) { //得到手机的GPS Log.i(TAG, "得到手机的GPS"); //把这个广播终止掉 abortBroadcast(); }else if("#*alarm*#".equals(body)){ Log.i(TAG, "播放报警音乐"); abortBroadcast(); }else if ("#*wipedata*#".equals(body)) { Log.i(TAG, "远程销毁数据"); abortBroadcast(); }else if ("#*lockscreen*#".equals(body)) { Log.i(TAG, "远程锁屏"); abortBroadcast(); } } } }
标签:android 手机管家
原文地址:http://blog.csdn.net/chenfuduo_loveit/article/details/41810815