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?
Hook up your tablet to your computer and let the application run on your tablet and check if it still returns true. The emulator is not reliable to draw a conclusion like that, since an emulator phone has a phone-application on it too while it can't call.
By the way, try to provide clear pictures with your question. The one you included is unreadable and I can't get any information out of it.
来源:https://stackoverflow.com/questions/34193753/can-tablets-make-calls-telephony