7

Possible Duplicate:
Enable GPS programatically like Tasker

Ok, I know there is same question asked before but all answer is "NO". It is proven that enable GPS can be done in coding. Don't believe? try out an application called "LOOKOUT". I believe there is some workaround in order to achieve this.

I had read through lookout AndroidManifest.xml, what i found out they only use

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

Anyone have idea how they managed to do this? what is the secret behind? I personally managed to do this only if the application is install as system app and also require two permission

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

My Code:

Settings.Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER, true);

thank you.

Community
  • 1
  • 1
Jason
  • 878
  • 2
  • 9
  • 21

1 Answers1

9

According to this post on the Lookout support forums, they are unable to programmatically enable GPS.

If Lookout could enable the GPS receiver remotely, then use the service, then turn it off – we would, but unfortunately there is no “disable GPS for everything other than Lookout” and if you have disabled the GPS receiver, no application can make use of it. Enabling the GPS receiver requires a user to do it manually.

Edit: It looks like in the new version of Lookout they are most likely now exploiting a security flaw to accomplish this. It is not guaranteed to continue to work, but according to an open Android bug report from April 2010, code similar to the following will successfully programmatically enable/disable GPS (at least until the flaw is fixed):

private void toggleGPS(boolean enable) {
    String provider = Settings.Secure.getString(getContentResolver(), 
        Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(provider.contains("gps") == enable) {
        return; // the GPS is already in the requested state
    }

    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"));
    context.sendBroadcast(poke);
}

Also, see the question "Enable GPS programmatically like Tasker" and the XDA thread mentioned there for more discussion on how people have used this method.

If you do use this method, you should make it clear to potential users of your application, since this is a HUGE potential privacy concern.

Community
  • 1
  • 1
Brian
  • 16,196
  • 3
  • 27
  • 28
  • Yes, that is old release. But this is possible in new release. Check out their help https://www.mylookout.com/help/ _Can you remotely turn on the GPS?_ **Yes!** Lookout makes use of the Android phone’s GPS receiver as efficiently as possible. When a locate is requested for an Android device, Lookout can remotely turn on the GPS while the locate is running and then turn it back off again (locates can run for a few minutes to get the best location results). This helps to conserve your phone’s battery life. Lookout only uses the GPS to get your location when you explicitly request it. – Jason Mar 30 '11 at 04:41
  • I had personally tested this as well. It works. – Jason Mar 30 '11 at 04:43
  • I just tried it now on a rooted device, and I can confirm it does appear to be able to enable the GPS (and it leaves it enabled even after it is finished). I wonder if they would still be able to do it on a non-rooted device. Have you tried it on a stock, non-rooted phone? – Brian Mar 30 '11 at 04:58
  • Hi Brian, yes it should work for non-rooted phone also. since it didnt request for root permission during enable. – Jason Mar 30 '11 at 06:15
  • I've edited my answer with the method they are likely using. Be aware that this is exploiting a security vulnerability and your users should be made aware of this. – Brian Mar 30 '11 at 14:39
  • Thanks Brian for the tips. will ask my user permission before doing this. – Jason Mar 31 '11 at 09:47
  • This security flaw was fixed today by Google: http://android.git.kernel.org/?p=platform/packages/apps/Settings.git;a=commit;h=4b21f7cd9424eeb83838071a4419912ee5d5e41d – Brian Apr 11 '11 at 17:49
  • I finally solved by this way. Certainly there is no way to turn on/off GPS through programmatically. Try codes below. final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$LocationSettingsActivity")); mContext.startActivity(intent); – theWook Feb 12 '14 at 05:08