2
2
3
3
import android .Manifest ;
4
4
import android .app .Activity ;
5
+ import android .app .AlertDialog ;
5
6
import android .bluetooth .BluetoothAdapter ;
6
7
import android .bluetooth .BluetoothDevice ;
7
8
import android .bluetooth .BluetoothManager ;
8
9
import android .bluetooth .le .ScanCallback ;
9
10
import android .bluetooth .le .ScanResult ;
11
+ import android .content .DialogInterface ;
10
12
import android .content .Intent ;
11
13
import android .content .pm .PackageManager ;
12
14
import android .os .Build ;
@@ -138,12 +140,28 @@ public void onItemClick(AdapterView<?> adapterview, View view, int position, lon
138
140
startScan ();
139
141
}
140
142
143
+ boolean popup_was_shown = false ;
144
+
141
145
@ NeedsPermission (Manifest .permission .ACCESS_FINE_LOCATION )
142
146
void startScan () {
143
147
if ((mBTAdapter != null ) && (!mIsScanning )) {
144
148
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
145
149
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
+ }
147
165
} else {
148
166
mBTAdapter .getBluetoothLeScanner ().startScan (mLeScanCallback );
149
167
mIsScanning = true ;
@@ -158,7 +176,6 @@ void startScan() {
158
176
}
159
177
}
160
178
}
161
-
162
179
void stopScan () {
163
180
if (mBTAdapter != null ) {
164
181
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
0 commit comments