public class OutCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String number = getResultData();
if ("20132013".equals(number)) {
Intent i = new Intent(context, LostFindActivity.class);
// 注意: 在activity上下文的外部开启 activity 需要指定下面的flag
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
// 停止这个特殊电话的外拨
setResultData(null);
}
}
}
外拨电话需要的权限和注册广播
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<receiver android:name="com.itheima.mobilesafe.receiver.OutCallReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>