手机响铃时调用的Activity的名称是什么

时间:2012-03-05 07:35:23

标签: android android-intent android-activity phone-call

当手机响铃时,我会看到一个屏幕,该屏幕会自动弹出两个按钮和来电者信息。这个屏幕来自哪里?什么活动?我知道它是从意图android.intent.action.PHONE_STATE调用的。但活动名称是什么,我该怎么做呢? enter image description here

1 个答案:

答案 0 :(得分:1)

以下是一些对您在来电时执行某些操作很有用的链接。 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>

和传入的广播接收器如:

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

}

希望对你有用。