Advertisement
Guest User

isGpsActive

a guest
May 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. public static void isLocationEnabled(final Context context) {
  2.         LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  3.         boolean gps_enabled = false;
  4.         boolean network_enabled = false;
  5.         try {
  6.             gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
  7.         } catch (Exception ex) {
  8.             FLog.d("Location", ex.toString());
  9.         }
  10.         try {
  11.             network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  12.         } catch (Exception ex) {
  13.             FLog.d("Location", ex.toString());
  14.         }
  15.         if (!gps_enabled && !network_enabled) {
  16.             // notify user
  17.             final AlertDialog.Builder dialog = new AlertDialog.Builder(context);
  18.             dialog.setTitle(context.getString(R.string.location_404));
  19.             dialog.setMessage(context.getResources().getString(R.string.gps_network_not_enabled));
  20.             dialog.setPositiveButton(context.getResources().getString(R.string.gotit), new DialogInterface.OnClickListener() {
  21.                 @Override
  22.                 public void onClick(DialogInterface paramDialogInterface, int paramInt) {
  23.                     // TODO Auto-generated method stub
  24.                     Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  25.                     context.startActivity(myIntent);
  26.                     //get gps
  27.                 }
  28.             });
  29.             dialog.setNegativeButton(context.getString(R.string.Cancel), new DialogInterface.OnClickListener() {
  30.                 @Override
  31.                 public void onClick(DialogInterface paramDialogInterface, int paramInt) {
  32.                     // TODO Auto-generated method stub
  33.                     paramDialogInterface.dismiss();
  34.                 }
  35.             });
  36.             dialog.show();
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement