mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Add Dialog if GPS not enabled
This commit is contained in:
parent
7e4a8bb125
commit
e8f306a023
1 changed files with 37 additions and 0 deletions
|
|
@ -1,10 +1,14 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -23,6 +27,7 @@ import fr.free.nrw.commons.theme.BaseActivity;
|
|||
import fr.free.nrw.commons.utils.UriSerializer;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -47,6 +52,7 @@ public class NearbyActivity extends BaseActivity {
|
|||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
checkGps();
|
||||
bundle = new Bundle();
|
||||
locationManager = new LocationServiceManager(this);
|
||||
locationManager.registerLocationManager();
|
||||
|
|
@ -83,6 +89,37 @@ public class NearbyActivity extends BaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected void checkGps() {
|
||||
LocationManager manager = (LocationManager)
|
||||
getSystemService(LOCATION_SERVICE);
|
||||
if(!manager.isProviderEnabled( LocationManager.GPS_PROVIDER )) {
|
||||
Timber.d("GPS is not enabled");
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
||||
alertDialogBuilder.setMessage("GPS is disabled in your device. Would you like to enable it?")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("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();
|
||||
|
||||
} else {
|
||||
Timber.d("GPS is enabled");
|
||||
}
|
||||
}
|
||||
|
||||
private void showMapView() {
|
||||
if (!isMapViewActive) {
|
||||
isMapViewActive = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue