0

I want to turn off sensors like GPS programaticaly. how to do that?

1 Answers1

2

Enable GPS

Intent intent=new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);

Disable GPS

Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", false);
sendBroadcast(intent);
IMRAN
  • 171
  • 6
  • [This answer](http://stackoverflow.com/questions/22528984/android-device-gps-on-off-programatically#22529296) suggests that this doesn't work in modern Android versions. I guess nowadays the user's action is needed to change the GPS state. – Markus Kauppinen May 06 '16 at 08:16
  • 1
    Thank you dear..Is it possible to turn off other sensors also? – lakshitha madusanka May 06 '16 at 09:31
  • yes it is possible to turn off like wifi,bluetooth,phone screen,gps – IMRAN May 06 '16 at 10:17
  • @lakshithamadusanka for wifi 'WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); wifiManager.setWifiEnabled(false);' you have to add permission in manifast ** ** – IMRAN May 06 '16 at 10:19
  • @lakshithamadusanka for bluetooth ******************** public static boolean setBluetooth(boolean enable) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); boolean isEnabled = bluetoothAdapter.isEnabled(); if (enable && !isEnabled) { return bluetoothAdapter.enable(); } else if(!enable && isEnabled) { return bluetoothAdapter.disable(); } return true; }***********************permissions are – IMRAN May 06 '16 at 10:24