Reputation: 111
I am developing calls and sms blocking app, I have encountered the problem where I can't get incoming number from 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.
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>
Upvotes: 2
Views: 1697
Reputation: 178
try adding this permissions, in my case this worked.
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
Upvotes: 1