1
private void toggleGPS() {
        Intent gpsIntent = new Intent();
        gpsIntent.setClassName("com.android.settings",
                "com.android.settings.widget.SettingsAppWidgetProvider");
        gpsIntent.addCategory("android.intent.category.ALTERNATIVE");
        gpsIntent.setData(Uri.parse("custom:3"));
        try {
            PendingIntent.getBroadcast(this, 0, gpsIntent, 0).send();
            // this.sendBroadcast(gpsIntent);
        } catch (CanceledException e) {
            e.printStackTrace();
        }
    }

Hi, please check above code which intends to toggle Android phone's GPS. But it seems not work on my Galaxy S3. Could anyone points out what is wrong with it?

The second question is that someone tries to analyse the source code of SettingsAppWidgetProvider.java. But I cannot find where it is, does anyone know?

Thanks!

Tom Xue
  • 3,169
  • 7
  • 40
  • 77

1 Answers1

1

1). You can't turn GPS on/off programatically (as far as I know), but you can ask the user to do so. Check this question

2). The source you are asking about can be found here

Community
  • 1
  • 1
Droidman
  • 11,485
  • 17
  • 93
  • 141
  • Thank you for this useful answer! I cannot find SettingsAppWidgetProvider.java in my android-sdk directory, what does this mean? – Tom Xue Sep 11 '13 at 16:09
  • well I couldn't find it in Android 4.2 either. They might have moved/renamed it. About manipulating GPS settings, there're a lot of related questions here on SO, please do some research. I've linked one of them in my answer – Droidman Sep 11 '13 at 16:18
  • Thank you! By using the first link you gave, I can turn on/off my GPS already. Just want to know more about the file. I will do more research. – Tom Xue Sep 11 '13 at 16:23