Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何检查设备是否具有GSM或GPS功能?_Android - Fatal编程技术网

Android 如何检查设备是否具有GSM或GPS功能?

Android 如何检查设备是否具有GSM或GPS功能?,android,Android,我试图上传关闭GPS并启用“平面模式”的应用程序,但由于错误导致Galaxy Tab Wi-Fi(M180W)而被拒绝。所以,我需要一些帮助,以确定该设备是否具有平面模式功能或GPS 全球定位系统: 平面模式: // plane mode if (option){ appPrefs.setCBoption(true); // read the airplane mode setting boolean isE

我试图上传关闭GPS并启用“平面模式”的应用程序,但由于错误导致Galaxy Tab Wi-Fi(M180W)而被拒绝。所以,我需要一些帮助,以确定该设备是否具有平面模式功能或GPS

全球定位系统:

平面模式:

// plane mode
        if (option){
            appPrefs.setCBoption(true);
            // read the airplane mode setting
            boolean isEnabled = Settings.System.getInt(
                      getApplicationContext().getContentResolver(), 
                      Settings.System.AIRPLANE_MODE_ON, 0) == 1;

            // toggle airplane mode
            Settings.System.putInt(
                    getApplicationContext().getContentResolver(),
                      Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);

            // Post an intent to reload
            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            intent.putExtra("state", !isEnabled);
            sendBroadcast(intent);
对于GSM:

TelephonyManager manager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);

if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
对于GPS:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

ArrayList<String> names = (ArrayList<String>) locationManager.getProviders(false);
LocationManager LocationManager=(LocationManager)getSystemService(Context.LOCATION\u服务);
ArrayList名称=(ArrayList)locationManager.getProviders(false);
如果名称为空,则GSM没有GPS:

TelephonyManager manager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);

if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
对于GPS:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

ArrayList<String> names = (ArrayList<String>) locationManager.getProviders(false);
LocationManager LocationManager=(LocationManager)getSystemService(Context.LOCATION\u服务);
ArrayList名称=(ArrayList)locationManager.getProviders(false);

如果名称为空,则没有GPS

听起来像是要使用
PackageManager.hasSystemFeature(…)

而且

/** Returns true if this device has support for GPS, otherwise false. */
public static boolean hasGpsSupport(Context context) {
    PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
}

听起来您想使用
PackageManager.hasSystemFeature(…)

而且

/** Returns true if this device has support for GPS, otherwise false. */
public static boolean hasGpsSupport(Context context) {
    PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
}

您无法手动启用GPS。用户应该这样做。即使您找到了一种方法,它也可能不适用于所有设备。是的,我知道我会制作一个弹出窗口,用户可以在其中选择:)我需要一种方法来确定设备是否具有此功能或此功能在该设备中是否为“空”。您无法手动启用GPS。用户应该这样做。即使您找到了一种方法,它也可能不适用于所有设备。是的,我知道我制作了一个弹出窗口,用户可以在其中选择:)我需要一种方法来确定设备是否具有此功能,或者此功能在该设备中是否为“空”