gpt4 book ai didi

android - PhoneStateListener onCallStateChanged 方法参数 "incoming number"在 Android 9.0 中为空?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:10:26 34 4
gpt4 key购买 nike

@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
if (incomingNumber == null || "".equals(incomingNumber)) {
return;
}
break;
}
}

我在 Android sdk27 以下遇到过同样的问题,我在 PhoneService 中启动 PhoneStateListener,

public  void startPhoneStateListener() {
mTelManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mTelManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}

但我只在 RootReceiver 中启动服务,而不是在 MainActivity 中启动服务,当我在 MainActivity 中启动 PhoneService 时,我修复了它。

  <receiver android:name=".receiver.RootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

但这只适用于 Android sdk 27​​ 以下,我不知道 Android 9.0,顺便说一句,我已经写了权限:

 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

最佳答案

根据 Behavior Changes for all apps in Android 9.0 :

Phone numbers associated with incoming and outgoing calls are visible in the phone state broadcast, such as for incoming and outgoing calls and are accessible from the PhoneStateListener class. Without the READ_CALL_LOG permission, however, the phone number field that's provided in PHONE_STATE_CHANGED broadcasts and through PhoneStateListener is empty.

如果您想要来电号码,您必须请求 READ_CALL_LOG 权限。

请注意,根据同一页面:

To read numbers from onCallStateChanged(), you need the READ_CALL_LOG permission only. You don't need the READ_PHONE_STATE permission.

关于android - PhoneStateListener onCallStateChanged 方法参数 "incoming number"在 Android 9.0 中为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54977469/

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