Android 如何检查设备是否具有GSM或GPS功能?
我试图上传关闭GPS并启用“平面模式”的应用程序,但由于错误导致Galaxy Tab Wi-Fi(M180W)而被拒绝。所以,我需要一些帮助,以确定该设备是否具有平面模式功能或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
// 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。用户应该这样做。即使您找到了一种方法,它也可能不适用于所有设备。是的,我知道我制作了一个弹出窗口,用户可以在其中选择:)我需要一种方法来确定设备是否具有此功能,或者此功能在该设备中是否为“空”