gpt4 book ai didi

android - 电话响铃时调用的Activity叫什么

转载 作者:行者123 更新时间:2023-11-29 02:06:50 24 4
gpt4 key购买 nike

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

最佳答案

这里有一些链接可以帮助您对来电执行某些操作。1) link2) 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;
}
}

希望对你有用。

关于android - 电话响铃时调用的Activity叫什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9563114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com