Как называется активность, которая вызывается, когда телефон звонит - PullRequest
2 голосов
/ 05 марта 2012

Когда звонит телефон, я получаю экран, который появляется автоматически с двумя кнопками и информацией о звонящем. Откуда этот экран? Какая активность? Я знаю, что он вызывается из намерения android.intent.action.PHONE_STATE. Но как называется деятельность и как я могу к ней добраться? enter image description here

1 Ответ

1 голос
/ 05 марта 2012

Вот несколько ссылок, которые полезны для выполнения некоторых действий при входящем звонке. 1) ссылка 2) ссылка

<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>

и приемник входящего вещания, например:

<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 расширяет 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");             


    }

и ваш 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;
    }
}

}

Надежда полезна для вас.

...