简体   繁体   English

PhoneStateListener返回null作为传入号码

[英]PhoneStateListener returns null as incoming number

I am developing calls and sms blocking app, I have encountered the problem where I can't get incoming number from phonestatelistener. 我正在开发呼叫和短信阻止应用程序,遇到了无法从phonestatelistener接收传入号码的问题。 My code looks like this: 我的代码如下所示:

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());

//reject call if number is matched to our blocking number //如果号码与我们的阻止号码匹配,则拒绝通话

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

So my programm works not as I expect it to work, cause it always returns null as incoming number. 所以我的程序无法正常工作,因为它总是返回null作为传入号码。

My manifest looks like this: 我的清单如下所示:

<?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"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用PhoneStateListener在Marshmallow中空入队号 - Null incoming number in Marshmallow using PhoneStateListener PhoneStateListener onCallStateChanged方法在Android 9.0中将“传入号码”设为空? - PhoneStateListener onCallStateChanged method params “incoming number” empty in Android 9.0? Android,TelephonyManager,PhoneStateListener和传入号码的乐趣 - Android, TelephonyManager, the joys of PhoneStateListener and incoming numbers Android PhoneStateListener 返回过去的呼叫 - Android PhoneStateListener returns past calls PhoneStateListener 没有给出拨打/呼叫的号码 - PhoneStateListener not giving the number dialed / called 传入视频群聊拨号器号码的意图为空 - intent on incoming hangouts dialer number is null 通过BroadcastReceiver监听传入的呼叫,无需PhoneStateIntentReceiver或PhoneStateListener - Listen incoming calls through BroadcastReceiver, without PhoneStateIntentReceiver or PhoneStateListener 如何在Android PhoneStateListener中获取断开的电话号码 - How to get the Disconnected Phone Number in android PhoneStateListener 为什么在意图额外的TelephonyManager.EXTRA_INCOMING_NUMBER中来电号码为空? - Why an incoming call number is null in intent extra TelephonyManager.EXTRA_INCOMING_NUMBER? 在android PIE 9中结束通话后来电号码为空 - Incoming number is null after ending the call in android PIE 9
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM