Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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();
    }
}
like image 954
Deepak Avatar asked Oct 01 '22 06:10

Deepak


1 Answers

 if (!((LocationManager) context.getSystemService(Context.LOCATION_SERVICE))
    .isProviderEnabled(LocationManager.GPS_PROVIDER)) {
 //prompt user to enable gps
 }else{
 //gps is enabled
 }
like image 197
praveen Avatar answered Oct 12 '22 10:10

praveen