Reputation: 338
I tried to upload application that turns off GPS and enables "plane mode", and I got rejected because of error that cause Galaxy Tab Wi-Fi(M180W). So I need some help to determine whether device has plane mode feature or 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:
// 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);
Upvotes: 0
Views: 841
Reputation: 8320
Sounds like you want to use 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);
}
and...
/** 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);
}
Upvotes: 0
Reputation: 58
For GSM :
TelephonyManager manager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
For GPS :
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
ArrayList<String> names = (ArrayList<String>) locationManager.getProviders(false);
if names is empty, you don't have GPS
Upvotes: 3