Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding configuration to disable location permission alert when starting the app #451

Open
wants to merge 1 commit into
base: v3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions src/android/LocationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class LocationManager extends CordovaPlugin implements BeaconConsumer {
private static final boolean DEFAULT_ENABLE_ARMA_FILTER = false;
private static final String REQUEST_BT_PERMISSION_NAME = "com.unarin.cordova.beacon.android.altbeacon.RequestBtPermission";
private static final boolean DEFAULT_REQUEST_BT_PERMISSION = true;
private static final String ENABLE_LOCATION_PERMISSION_ALERT = "com.unarin.cordova.beacon.android.altbeacon.EnableLocationPermissionAlert";
private static final boolean DEFAULT_ENABLE_LOCATION_PERMISSION_ALERT = true;
private static final int DEFAULT_FOREGROUND_SCAN_PERIOD = 1100;
private static int CDV_LOCATION_MANAGER_DOM_DELEGATE_TIMEOUT = 30;
private static final int BUILD_VERSION_CODES_M = 23;
Expand Down Expand Up @@ -315,32 +317,37 @@ private void tryToRequestMarshmallowLocationPermission() {
"supported version of Android.");
return;
}

final boolean enableLocationPermissionAlert = this.preferences.getBoolean(
ENABLE_LOCATION_PERMISSION_ALERT, DEFAULT_ENABLE_LOCATION_PERMISSION_ALERT);

if (enableLocationPermissionAlert) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("This app needs location access");
builder.setMessage("Please grant location access so this app can detect beacons.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@SuppressLint("NewApi")
@Override
public void onDismiss(final DialogInterface dialog) {

final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("This app needs location access");
builder.setMessage("Please grant location access so this app can detect beacons.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@SuppressLint("NewApi")
@Override
public void onDismiss(final DialogInterface dialog) {

try {
requestPermissionsMethod.invoke(activity,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
PERMISSION_REQUEST_COARSE_LOCATION
);
} catch (IllegalAccessException e) {
Log.e(TAG, "IllegalAccessException while requesting permission for " +
"ACCESS_COARSE_LOCATION:", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "InvocationTargetException while requesting permission for " +
"ACCESS_COARSE_LOCATION:", e);
try {
requestPermissionsMethod.invoke(activity,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
PERMISSION_REQUEST_COARSE_LOCATION
);
} catch (IllegalAccessException e) {
Log.e(TAG, "IllegalAccessException while requesting permission for " +
"ACCESS_COARSE_LOCATION:", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "InvocationTargetException while requesting permission for " +
"ACCESS_COARSE_LOCATION:", e);
}
}
}
});
});

builder.show();
builder.show();
}

} catch (final IllegalAccessException e) {
Log.w(TAG, "IllegalAccessException while checking for ACCESS_COARSE_LOCATION:", e);
Expand Down