gpt4 book ai didi

android - PhoneStateListener 返回 null 作为传入号码

转载 作者:行者123 更新时间:2023-11-29 02:39:46 25 4
gpt4 key购买 nike

我正在开发电话和短信拦截应用程序,我遇到了无法从 phonestatelistener 获取来电号码的问题。我的代码如下所示:

public void onCallStateChanged(int state, String incomingNumber) {

switch (state) {
case TelephonyManager.CALL_STATE_IDLE:



break;
case TelephonyManager.CALL_STATE_OFFHOOK:

break;
case TelephonyManager.CALL_STATE_RINGING:





System.out.println("incoming number PhoneStateListener:" + incomingNumber);

if (sBlockCall>0){
MuteAudio(getContext());

//如果号码与我们的阻止号码匹配,则拒绝调用

                    boolean callShouldBeBlocked = true;
for(int i = 0; i<sWhiteList.size(); i++){
if(sIncomingNumber.contains(sWhiteList.get(i).mNumber)){
UnMuteAudio(getContext());
System.out.println("CONTACT IS IN WHITE LIST");

callShouldBeBlocked = false;

break;
}
}
if(callShouldBeBlocked){
System.out.println("BLOCK CALL");
disconnectPhoneItelephony();

}


} else {
UnMuteAudio(getContext());
}

//IT WORKS






break;
}
}

所以我的程序没有像我期望的那样工作,因为它总是返回 null 作为传入数字。

我的 list 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="oleksandr.ivanets.dontwakemeapp">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>



<receiver
android:name=".PhoneStateReceiver"
android:enabled="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="999999999">
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>




</application>

</manifest>

最佳答案

尝试添加此权限,在我的例子中这有效。

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

关于android - PhoneStateListener 返回 null 作为传入号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45013379/

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