Skip to content

Commit

Permalink
Check if location services are enabled otherwise go to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrelevy committed Apr 8, 2012
1 parent 8ceb55e commit fe50e80
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<string name="button_ar">Réalitée augmentée</string>

<string name="label_list_aoc">Liste des AOC de la commune : </string>
<string name="message_activate_location">Les services de géolocalisation (GPS ou réseau) semblent désactivés !\n\nVoulez-vous en activer un pour utiliser cette application ?</string>


</resources>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<string name="button_ar">Augmented reality</string>

<string name="label_list_aoc">List of the AOC\'s town : </string>
<string name="message_activate_location">Location services (GPS and network) seem to be disabled!\n\nDo you want to enable one of them to use this application ?</string>

</resources>
43 changes: 43 additions & 0 deletions src/com/franceaoc/app/ui/activity/DashboardActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
package com.franceaoc.app.ui.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuItem;

Expand Down Expand Up @@ -104,4 +108,43 @@ private void startOptions()
Intent intent = new Intent(Constants.ACTION_OPTIONS);
startActivity(intent);
}


@Override
protected void onResume()
{
super.onResume();
final LocationManager manager = (LocationManager) getSystemService( LOCATION_SERVICE );
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
buildAlertMessageNoLocation();
}
}


private void buildAlertMessageNoLocation()
{
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage( R.string.message_activate_location ).setCancelable(false).setPositiveButton( getString( android.R.string.yes ), new DialogInterface.OnClickListener()
{

@Override
public void onClick( final DialogInterface dialog, final int id)
{
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
}).setNegativeButton( getString( android.R.string.no ) , new DialogInterface.OnClickListener()
{

@Override
public void onClick(final DialogInterface dialog, final int id)
{
dialog.cancel();
finish();
}
});
final AlertDialog alert = builder.create();
alert.show();
}

}

0 comments on commit fe50e80

Please sign in to comment.