Java – Can a tablet make phone calls? (Phone)

Can a tablet make phone calls? (Phone)… here is a solution to the problem.

Can a tablet make phone calls? (Phone)

I have permissions in list:

 <uses-feature 
   android:name="android.permission.READ_PHONE_STATE"  android:required="false" />

A code that checks if the phone is in use may initiate a security exception for a device such as a tablet that cannot receive calls. So, I made this method to check if the device can use TelephonyManager:

private boolean doesUserHavePermission(){
    PackageManager pm = getPackageManager();
    final boolean deviceHasPhone = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
    return deviceHasPhone;
}

In the code where I actually check if a phone is received, I put an if statement to see if 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 toast to checking the return value of the boolean method doesUserHavePermission(), it always returns true, even on my emulator tablet… It’s weird because the tablet can’t call/receive calls….

The emulator device I tested was:

enter image description here

Why is the boolean value always true, and how can I change my method appropriately?

Solution

Connect your tablet

to your computer, let the app run on your tablet and check if it still returns true.
It is unreliable for the emulator to come to such a conclusion because there is also a phone app on the emulator phone, but it cannot make calls.

By the way, please try to provide a clear picture with your question. The one you provided is unreadable and I can’t get any information from it.

Related Problems and Solutions