0

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

全球定位系统:

//gps
        final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
        appPrefs.setGPS(manager.isProviderEnabled( LocationManager.GPS_PROVIDER));
        if (manager.isProviderEnabled( LocationManager.GPS_PROVIDER) && manager!=null){
        Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
        startActivity(myIntent);
        Toast toast = Toast.makeText(getApplicationContext(), "Please turn off GPS and hit back", Toast.LENGTH_LONG);
        toast.show();

平面模式:

// 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);
4

2 回答 2

3

对于 GSM :

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

if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)

全球定位系统:

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

ArrayList<String> names = (ArrayList<String>) locationManager.getProviders(false);

如果名称为空,则您没有 GPS

于 2013-07-30T11:55:46.980 回答
0

听起来你想使用PackageManager.hasSystemFeature(...).

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

和...

/** 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);
}
于 2015-02-14T10:34:15.417 回答