Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call intercept on android

currently, is call intercept on android possible? to a level where i can get the phone number when a call is made.

like image 699
shebelaw Avatar asked May 04 '11 14:05

shebelaw


2 Answers

yes you can .... extend BroadcastReceiver and override onReceive as the following

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 :)
            }
        }

    }

and you will need to add your BroadcastReceiver on the AndroidManifest.xml as the following

<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>
like image 90
shereifhawary Avatar answered Sep 29 '22 19:09

shereifhawary


You can use PhoneStateListener with a custom broadcast receiver, which gets you onCallStateChanged(int state, String incomingNumber).

(You'll also need <uses-permission android:name="android.permission.READ_PHONE_STATE" /> in your AndroidManifest.)

like image 32
Ben Williams Avatar answered Sep 29 '22 21:09

Ben Williams