5

I showed prompt to user to enable gps settings,but how can I check user really enabled the gps location on his phone?

private static void showGPSDisabledAlertToUser() {
        // TODO Auto-generated method stub
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ChatSDK.getSDKInstance().activity);
        alertDialogBuilder
                .setMessage(
                        "GPS is disabled in your device. Would you like to enable it?")
                .setCancelable(false)
                .setPositiveButton("Goto Settings Page To Enable GPS",

                new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                Intent callGPSSettingIntent = new Intent(
                                        android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                ChatSDK.getSDKInstance().activity.startActivity(callGPSSettingIntent);
                            }
                        });
//      alertDialogBuilder.setNegativeButton("Cancel",
//              new DialogInterface.OnClickListener() {
//                  public void onClick(DialogInterface dialog, int id) {
//                      dialog.cancel();
//                  }
//              });
        AlertDialog alert = alertDialogBuilder.create();
        alert.show();
    }
}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
Deepak
  • 1,669
  • 1
  • 18
  • 28
  • possible duplicate of [How do I find out if the GPS of an Android device is enabled](http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is-enabled) – Raptor Mar 20 '14 at 07:25
  • keep one boolean and set as false initially and change it to true while sending the intent. and check in onResume if if is true check the gps connectivity there and change the boolean to false. – Tamilselvan Kalimuthu Mar 20 '14 at 07:27
  • @user3152953 check my answer, if you want to something else give me details , – CompEng Mar 20 '14 at 07:28

2 Answers2

4
 if (!((LocationManager) context.getSystemService(Context.LOCATION_SERVICE))
    .isProviderEnabled(LocationManager.GPS_PROVIDER)) {
 //prompt user to enable gps
 }else{
 //gps is enabled
 }
praveen
  • 420
  • 4
  • 18
0

@user3152953

you can write this to check

boolean isGPS ;
 isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);

 if(isGPS)
  {
     //gps is open already
  }
 else
 {
    //gps is close already
 }
CompEng
  • 7,161
  • 16
  • 68
  • 122