I have a permission in manifest:
<uses-feature
android:name="android.permission.READ_PHONE_STATE" android:required="false" />
The code that checks if the telephone is being used would probably start a security exception for devices like tablets, who can't receive calls. So, I made this method to check whether or not the device can use the TelephonyManager:
private boolean doesUserHavePermission(){
PackageManager pm = getPackageManager();
final boolean deviceHasPhone = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
return deviceHasPhone;
}
And in the code where I actually check if a call is being received, I put an if statement to see whether the device has or doesn't have the phone:
private PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (doesUserHavePermission()) { //I ADDED THIS
if (state == TelephonyManager.CALL_STATE_RINGING) {
onPhoneCallInterrupt(); //Method I made that mutes audio for phone call
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
onPhoneCallInterrupt(); //Method I made that mutes audio for phone call
}
}
}
};
I made a toast to check the return value of that boolean method doesUserHavePermission()
and it always returns true, even on my emulator tablet...that's odd because tablets can't make/receive calls...
The emulator device I was testing this on was:
Why is the boolean always true, and how should I alter my method appropriately?