Can tablets make calls? (Telephony)

倾然丶 夕夏残阳落幕 提交于 2019-12-07 08:07:32

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!