Enable GPS on root devices

This question of turning GPS GPS on / off on the Android program has been discussed many times, and the answer is always the same: you cannot for security / privacy reasons. But is there any way for rooted devices to enable gps with some changes in system settings.

+4
source share
2 answers

There is a working solution based on the root. See in one of my answers in the profile. Now I can not clarify (in the hospital). But for now, you need root and busybox. I am trying to get it working without busybox. Tested with 2.3.5 4.0.1 and 4.1.2

http://rapidshare.com/files/3977125468/GPSToggler-20130214.7z

+2
source

You can enable / disable GPS programmatically up to Android 2.2 (API 8)

Here is the code I'm using

public class GpsOnOff extends Activity implements OnClickListener { Button onButton; Button offButton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); onButton = (Button) findViewById(R.id.btnON); offButton = (Button) findViewById(R.id.btnOFF); onButton.setOnClickListener(this); offButton.setOnClickListener(this); } @Override public void onClick(View v) { if(v==onButton){ //this will work upto 2.2 api only turnGPSOn(); //this will work for all but it Navigate to GPS setting screen only //not change settings automatically /*Intent in = new Intent(android.provider.Settings .ACTION_LOCATION_SOURCE_SETTINGS); startActivity(in);*/ Toast.makeText(getApplicationContext(), "gps enabled", 1).show(); } else if(v==offButton){ turnGPSOff(); Toast.makeText(getApplicationContext(), "gps disabled", 1).show(); } } private void turnGPSOn(){ String provider = Settings.Secure .getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if(!provider.contains("gps")){ //if gps is disabled final Intent poke = new Intent(); poke.setClassName("com.android.settings", "com.android.settings.widget .SettingsAppWidgetProvider"); poke.addCategory(Intent.CATEGORY_ALTERNATIVE); poke.setData(Uri.parse("3")); sendBroadcast(poke); } } private void turnGPSOff(){ String provider = Settings.Secure.getString( getContentResolver(), Settings.Secure .LOCATION_PROVIDERS_ALLOWED); if(provider.contains("gps")){ //if gps is enabled final Intent poke = new Intent(); poke.setClassName("com.android.settings", "com.android.settings.widget .SettingsAppWidgetProvider"); poke.addCategory(Intent.CATEGORY_ALTERNATIVE); poke.setData(Uri.parse("3")); sendBroadcast(poke); } } } 

Make sure you need to add below two permissions to the manifest file

 <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> 
0
source

All Articles