Skip to content

Commit 30ad185

Browse files
committed
Permission Popup
1 parent 2f8fa03 commit 30ad185

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

.gitignore

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
*.iml
22
.gradle
33
/local.properties
4-
/.idea/caches
5-
/.idea/libraries
6-
/.idea/modules.xml
7-
/.idea/workspace.xml
8-
/.idea/navEditor.xml
9-
/.idea/assetWizardSettings.xml
4+
/.idea
5+
/build
106
.DS_Store
117
/build
128
/captures

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/build
2+
/release

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
applicationId "com.atcnetz.de.notification"
77
minSdkVersion 21
88
targetSdkVersion 29
9-
versionCode 72
9+
versionCode 73
1010
versionName = versionCode
1111
}
1212
buildTypes {

app/src/main/java/com/atcnetz/de/notification/ScanActivity.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import android.Manifest;
44
import android.app.Activity;
5+
import android.app.AlertDialog;
56
import android.bluetooth.BluetoothAdapter;
67
import android.bluetooth.BluetoothDevice;
78
import android.bluetooth.BluetoothManager;
89
import android.bluetooth.le.ScanCallback;
910
import android.bluetooth.le.ScanResult;
11+
import android.content.DialogInterface;
1012
import android.content.Intent;
1113
import android.content.pm.PackageManager;
1214
import android.os.Build;
@@ -138,12 +140,28 @@ public void onItemClick(AdapterView<?> adapterview, View view, int position, lon
138140
startScan();
139141
}
140142

143+
boolean popup_was_shown = false;
144+
141145
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
142146
void startScan() {
143147
if ((mBTAdapter != null) && (!mIsScanning)) {
144148
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
145149
if (this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
146-
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
150+
if (!popup_was_shown) {
151+
popup_was_shown = true;
152+
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
153+
alertDialogBuilder.setMessage("This app collects location data to enable bluetooth scanning even when the app is closed or not in use.");
154+
alertDialogBuilder.setTitle("Location permission");
155+
alertDialogBuilder.setNegativeButton("ok", new DialogInterface.OnClickListener() {
156+
@Override
157+
public void onClick(DialogInterface dialogInterface, int i) {
158+
dialogInterface.cancel();
159+
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
160+
}
161+
});
162+
AlertDialog alertDialog = alertDialogBuilder.create();
163+
alertDialog.show();
164+
}
147165
} else {
148166
mBTAdapter.getBluetoothLeScanner().startScan(mLeScanCallback);
149167
mIsScanning = true;
@@ -158,7 +176,6 @@ void startScan() {
158176
}
159177
}
160178
}
161-
162179
void stopScan() {
163180
if (mBTAdapter != null) {
164181
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

0 commit comments

Comments
 (0)