我尝试上传关闭GPS并启用“平面模式”的应用程序,但由于导致 Galaxy Tab Wi-Fi(M180W)的错误而被拒绝了。所以我需要一些帮助来确定设备是否具有平面模式功能或GPS。
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);
答案 0 :(得分:3)
对于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);
如果名称为空,则表示您没有GPS
答案 1 :(得分: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);
}