在android上调用intercept

时间:2011-05-04 14:34:52

标签: android phone-number intercept

目前,是否可以在android上调用拦截?到达可以在拨打电话时获得电话号码的级别。

2 个答案:

答案 0 :(得分:4)

是的,你可以......扩展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>

答案 1 :(得分:1)

您可以将PhoneStateListener与自定义broadcast receiver一起使用,从而获得onCallStateChanged(int state, String incomingNumber)

(您的AndroidManifest中还需要<uses-permission android:name="android.permission.READ_PHONE_STATE" />。)