1

I'm writing small app for our workers, to work in terrain, and I have some idea. We want to track their location for better logistics and better work control.

App is not a problem for me, but button to turning on/off GPS/Locations Manager. Is there any possibility to set GPS always ON, and unable to turn OFF, or maybe something that will detect turning OFF, and turn GPS back ON every few seconds (?bash script?).

I've rooted my device (GALAXY GIO) and I have full access to CLI. I know how to disable/enable almost every device, but GPS is still puzzle for me...

Is it possible to do something like that without changing ROM? Current ROM is 2.3.6 Gingerbread.

  • Thanks in advance!, Mike
Rais Alam
  • 6,970
  • 12
  • 53
  • 84
user1802499
  • 43
  • 1
  • 4
  • I read your question again, and i think you mean GPS enabled/disabled by user (in the device settings) rather than GPS ON/OFF. They are very different things. – Mister Smith Dec 21 '12 at 09:41

2 Answers2

1

Use services and place this code in your services.

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);
    /*
     * Toast.makeText(getApplicationContext(), "GPS On Success",
     * Toast.LENGTH_SHORT).show();
     */
}
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
User
  • 1,251
  • 1
  • 14
  • 19
  • This code exploits a bug. No guarantee this is going to work in the future. More info here: http://stackoverflow.com/a/5305835/813951 – Mister Smith Dec 21 '12 at 09:34
  • Update: Reading the comments in the question I linked, seems that it has already been fixed in Gingerbread, so it won't work. – Mister Smith Dec 21 '12 at 09:55
1

There's no reliable way of doing what you need, other than exploits (which looks like only work for 2.2 and some 2.3 builds) and custom ROMs (If you can find one that does this).

In Android, the user has control over most functions. Android is aimed for personal use, and it's not very well suited for this kind things. You migh be better off switching to another platform (e.g.: BlackBerry) that allowed you to do this, or even reading data via bluetooth from a GPS tracking device that is turned on always. They can still disable bluetooth, so you migh need to search for a fully autonomous GPS tracking device (there are many available in the market, some of them also have a SIM card so they can send data in real time).

As a final note, I'd say most workers will gladly enable the GPS if they are required to do so, and in case they disable it, you can still detect it and report to a WS or log, in order to ask them for an explanation later.

Mister Smith
  • 27,417
  • 21
  • 110
  • 193