【问题标题】:What is the name of the Activity that is called when the phone is ringing电话响铃时调用的 Activity 的名称是什么
【发布时间】:2012-03-05 07:35:23
【问题描述】:

当电话响起时,我会自动弹出一个屏幕,其中包含两个按钮和来电者信息。这个屏幕是哪里来的?什么活动?我知道它是从意图 android.intent.action.PHONE_STATE 调用的。但是活动名称是什么,我怎样才能找到它?

【问题讨论】:

  • 使用广播发送方呼叫号码,使用广播接收方接听来电。不需要上面屏幕的活动名称。

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


【解决方案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;
    }
}

}

希望对你有用。

【讨论】:

  • 谢谢!有什么办法可以隐藏上面的屏幕?我想定制自己的屏幕。
  • 是的。从宽卡接收器调用您的定制设计活动。您在清单中的活动。检查编辑的答案。
  • 非常感谢!但是,acceptreject 第一次出现时,您会看到默认屏幕出现一瞬间(我认为这与堆栈有关)。有什么办法绕过它?还有可以自定义的传出屏幕呢?
  • 我从未尝试过,但我认为这是可能的。还有 android 2.3.x 和之后的版本,你不能使用你的自定义按钮接听电话,因为他们在那之后受到了限制。
  • 您的自定义传入屏幕和默认(电话)都试图在屏幕上显示,因此不确定您的屏幕是否始终位于默认屏幕的顶部。 '' 用于隐藏默认屏幕。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多