Java tutorial
//package com.java2s; import android.app.PendingIntent; import android.app.PendingIntent.CanceledException; import android.content.Context; import android.content.Intent; import android.location.LocationManager; import android.net.Uri; import android.util.Log; public class Main { private static final String TAG = "NUtil"; public static void openGPS(Context context) { Log.d(TAG, "openGPS"); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { 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 (CanceledException e) { Log.d(TAG, "openGPS exception:" + e.getMessage()); e.printStackTrace(); } } } }