Java – can tablets make phone calls? (telephone)
I have permissions in the list:
<uses-feature
android:name="android.permission.READ_PHONE_STATE" android:required="false" />
The code to check whether the phone is in use may start a security exception for devices that cannot answer the phone, such as tablets. Therefore, I use this method to check whether the device can use the telephonymanager:
private boolean doesUserHavePermission(){
PackageManager pm = getPackageManager();
final boolean deviceHasPhone = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
return deviceHasPhone;
}
In the code that I actually check whether a call is received, I enter an IF statement to check whether the device has a 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 the boolean method douserhavepermission(), which always returns true, even on my simulator tablet... It's strange because the tablet can't make / receive calls
The simulator equipment I am testing is:
Why is the Boolean always true? How can I change my method appropriately?
resolvent:
Connect the tablet to the computer, let the application run on the tablet, and check whether it still returns true. The emulator is not reliable to come to this conclusion because the emulator also has a telephone application on the phone, but it can't call
By the way, try to provide a clear picture with your question. The one you contain is unreadable and I can't get any information from it