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?