在android上调用intercept
作者:互联网
目前,是否可以在android上调用拦截?到达我可以在拨打电话时获得电话号码的级别.
解决方法:
是的,你可以……扩展BroadcastReceiver并覆盖onReceive,如下所示
public class CallListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String phoneNumber = intent.getExtras().getString(Intent.EXTRA_PHONE_NUMBER);
System.out.println(phoneNumber);
if (phoneNumber != null&& CallService.phoneNumber.equals("ANY_NUMBER_YOU_WANNA_INTERCEPT_ON")) {
//do what you want to do :)
}
}
}
您将需要在AndroidManifest.xml上添加您的BroadcastReceiver,如下所示
<receiver android:name=".CallListener" android:permission="android.permission.PROCESS_OUTGOING_CALLS">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
标签:android,phone-number,intercept 来源: https://codeday.me/bug/20190521/1148618.html