Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void isLocationEnabled(final Context context) {
- LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
- boolean gps_enabled = false;
- boolean network_enabled = false;
- try {
- gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
- } catch (Exception ex) {
- FLog.d("Location", ex.toString());
- }
- try {
- network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
- } catch (Exception ex) {
- FLog.d("Location", ex.toString());
- }
- if (!gps_enabled && !network_enabled) {
- // notify user
- final AlertDialog.Builder dialog = new AlertDialog.Builder(context);
- dialog.setTitle(context.getString(R.string.location_404));
- dialog.setMessage(context.getResources().getString(R.string.gps_network_not_enabled));
- dialog.setPositiveButton(context.getResources().getString(R.string.gotit), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface paramDialogInterface, int paramInt) {
- // TODO Auto-generated method stub
- Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
- context.startActivity(myIntent);
- //get gps
- }
- });
- dialog.setNegativeButton(context.getString(R.string.Cancel), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface paramDialogInterface, int paramInt) {
- // TODO Auto-generated method stub
- paramDialogInterface.dismiss();
- }
- });
- dialog.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement