Skip to content

Commit

Permalink
Solicitud de permisos de localización
Browse files Browse the repository at this point in the history
  • Loading branch information
Albrodiaz committed Nov 29, 2022
1 parent 19c7a2d commit 5b43c46
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
package="es.travelworld.travelling">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ private void checkLocationPermission() {
registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), result -> {
Boolean fineLocationGranted = result.getOrDefault(permissions[1], false);
Boolean coarseLocationGranted = result.getOrDefault(permissions[0], false);
if (fineLocationGranted != null && !fineLocationGranted || coarseLocationGranted != null && !coarseLocationGranted) {
if (fineLocationGranted != null && !fineLocationGranted ||
coarseLocationGranted != null && !coarseLocationGranted) {
showPermissionInfo();
} else {
userWelcome();
Expand All @@ -61,9 +62,13 @@ private void showPermissionInfo() {
.setTitle(R.string.requiredPermission)
.setMessage(R.string.permissionDescription)
.setCancelable(false)
.setPositiveButton(R.string.understood,
.setNeutralButton(R.string.exit, (dialog, which) -> {
dialog.dismiss();
finish();
})
.setPositiveButton(R.string.settings,
(dialog, which) -> {
dialog.cancel();
dialog.dismiss();
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
finish();
})
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@
<string name="vehicle_title">Tipos de vehículos</string>
<string name="requiredPermission">Permisos necesarios</string>
<string name="permissionDescription">Es necesario activar la localización para poder ofrecer las mejores ofertas en alojamientos</string>
<string name="settings">Ajustes</string>
<string name="exit">Salir</string>
</resources>

0 comments on commit 5b43c46

Please sign in to comment.