Search code examples
androidandroid-intentandroid-activityphone-call

What is the name of the Activity that is called when the phone is ringing


When the phone rings I get a screen that pops up automatically with two buttons and the caller info. Where is this screen coming from ? What Activity? I know it is called from the intent android.intent.action.PHONE_STATE. But what is the activity name and how can I get to it? enter image description here


Solution

  • Here are some links that is useful to you to perform some action on incoming call. 1) link 2) link

    <activity android:name=".AcceptReject" android:theme="@android:style/Theme.NoTitleBar"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.ANSWER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    

    and incoming broadcast receiver like:

    <receiver android:name=".IncomingCallReceiver" >
            <intent-filter >             
                <action android:name="android.intent.action.PHONE_STATE" />
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />                               
            </intent-filter>
        </receiver>
    

    IncomingCallReceiver extends BroadcastReceiver :

    if (intent.getAction()
                .equals("android.intent.action.NEW_OUTGOING_CALL")) {
            Log.i("System out", "IN OUTGOING CALL......... :IF");
            MyPhoneStateListener phoneListener = new MyPhoneStateListener(
                        context);
                TelephonyManager telephony = (TelephonyManager) context
                        .getSystemService(Context.TELEPHONY_SERVICE);
                telephony.listen(phoneListener,
                        PhoneStateListener.LISTEN_CALL_STATE);
        }    else {         
                Log.i("System out", "IN INCOMING CALL.........:else:receiver");             
    
    
        }
    

    and your MyPhoneStateListener

    class MyPhoneStateListener extends PhoneStateListener {
    private final Context context;
    private boolean NOTOFFHOOK = false; 
    public MyPhoneStateListener(Context context) {
        this.context = context;
    }
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
        case TelephonyManager.CALL_STATE_IDLE: // by default phone is in idle state
            Log.d("System out", "IDLE");
            NOTOFFHOOK = true;      
            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:   // when user receive call this method called
            Log.d("System out", "OFFHOOK, it flag: " + NOTOFFHOOK);
    
            if (NOTOFFHOOK == false) {
                // do your work on receiving call.
            }
            break;
        case TelephonyManager.CALL_STATE_RINGING:   // while ringing 
            Log.d("System out", "RINGING");
            // do your work while ringing.
    
            break;
        }
    }
    

    }

    Hope useful to you.