Last active
June 2, 2016 13:18
-
-
Save pierangelo1982/dce786e228384a305efabdb130f70e47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
public class ExampleApp extends Activity { | |
/** Called when the activity is first created. */ | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); | |
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ | |
Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show(); | |
}else{ | |
showGPSDisabledAlertToUser(); | |
} | |
} | |
private void showGPSDisabledAlertToUser(){ | |
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); | |
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); | |
startActivity(callGPSSettingIntent); | |
} | |
}); | |
alertDialogBuilder.setNegativeButton("Cancel", | |
new DialogInterface.OnClickListener(){ | |
public void onClick(DialogInterface dialog, int id){ | |
dialog.cancel(); | |
} | |
}); | |
AlertDialog alert = alertDialogBuilder.create(); | |
alert.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment