通过拨号直接进入手机防盗页面,需要设置一个拨号的广播接收器,创建一个CallOutReceiver,基类为BroadcastReceiver:
package com.example.mobilesafe.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.example.mobilesafe.LostProtectedActivity;
/**
* Created by sing on 13-12-26.
* desc:
*/
public class CallOutReceiver extends BroadcastReceiver {
//设定进入手机防盗的号码
private static final String enterLostProtectedPhoneNumber = "110";
public void onReceive(Context context, Intent intent) {
//获取广播发送来的数据
String number = getResultData();
if (number.equals(enterLostProtectedPhoneNumber)) {
Intent lostProtectedIntent = new Intent(context, LostProtectedActivity.class);
//为lostProtectedIntent设置新的任务栈
lostProtectedIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(lostProtectedIntent);
//拦截该外拨号码,拨号记录中不会显示此次拨号
setResultData(null);
}
}
}
添加权限:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
以及接收器:
<receiver android:name=".receiver.CallOutReceiver" >
<intent-filter android:priority="1000">
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
对于有序广播权限范围是-1000~1000,CallOutReceiver的权限设置为1000,即最高权限。并设置广播接受动作为:android.intent.action.NEW_OUTGOING_CALL,也即电话拨出时触发该接收器。
setResultData(null);
使得此次拨号记录不在拨号记录中显示。