Android Device phone call ability

前端 未结 7 910
粉色の甜心
粉色の甜心 2020-12-02 23:09

How can I tell whether a given device has the ability to make phone calls?

For example, my Galaxy Tablet cannot initiate call, its not a phone. I want to detect tha

相关标签:
7条回答
  • 2020-12-02 23:39

    I have not checked this yet but here is a solution I came up with that seems like it should work fine. I don't think this requires any special permissions since it is just looking for bools set by the manufacture.

    static boolean isRunningOnPhone(Context context){
        UiModeManager uiModeManager = (UiModeManager) context.getSystemService(UI_MODE_SERVICE);
        PackageManager packageManager = context.getPackageManager();
        boolean a = packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
        boolean b = packageManager.hasSystemFeature(PackageManager.FEATURE_SIP_VOIP) || context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA) || context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA);
        boolean c = packageManager.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN);
        boolean d;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            d = packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
        }else {
            d = !(uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR);
        }
        boolean e = !(uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION);
        boolean f = uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_APPLIANCE;
        boolean g = true;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            g = !(uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_WATCH);
        }
    
        return a && b && c && d && e && f && g;
    }
    
    0 讨论(0)
提交回复
热议问题