-1

I want to help my app user force open GPS when they closed their GPS, i do it like below code:

public static void openGPS(final Context context) {
    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(context, 0, gpsIntent, 0).send();
    } catch (PendingIntent.CanceledException e) {
        Toast.makeText(context, "force open GPS failed:" + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}

but i cann't open the GPS, and i don't get the exception Toast like above.I don't have an idea to resolve it, could anyone help me?

MayGodBlessYou
  • 649
  • 6
  • 19
  • I think you should find the solution here : https://stackoverflow.com/questions/43518520/how-to-ask-user-to-enable-gps-at-the-launch-of-application – Vikas Nov 16 '18 at 05:49
  • @Vikas but I'm in china, the GMS is unaccessiable to my app user – MayGodBlessYou Nov 22 '18 at 05:14

1 Answers1

1

Try adding the whole code in try catch block and check for generic Exception class and see what is the error.

Vikas
  • 136
  • 6