Skip to content

Commit 1e74b0b

Browse files
+ added Location Services enabled check for Android 6.0 devices
- updated project for Android Studio 1.4.1
1 parent a55872a commit 1e74b0b

File tree

8 files changed

+112
-66
lines changed

8 files changed

+112
-66
lines changed

.idea/checkstyle-idea.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app.iml

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,33 @@
7171
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
7272
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
7373
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
74-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.0/jars" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/jars" />
7575
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.2.0/jars" />
76-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.0/jars" />
77-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/7.8.0/jars" />
78-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/7.8.0/jars" />
79-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/7.8.0/jars" />
80-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appinvite/7.8.0/jars" />
81-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appstate/7.8.0/jars" />
82-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.8.0/jars" />
83-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-cast/7.8.0/jars" />
84-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-drive/7.8.0/jars" />
85-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-fitness/7.8.0/jars" />
86-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-games/7.8.0/jars" />
87-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-gcm/7.8.0/jars" />
88-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-identity/7.8.0/jars" />
89-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-location/7.8.0/jars" />
90-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-maps/7.8.0/jars" />
91-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-nearby/7.8.0/jars" />
92-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-panorama/7.8.0/jars" />
93-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-plus/7.8.0/jars" />
94-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-safetynet/7.8.0/jars" />
95-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-vision/7.8.0/jars" />
96-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-wallet/7.8.0/jars" />
97-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-wearable/7.8.0/jars" />
98-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services/7.8.0/jars" />
76+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.0/jars" />
77+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/8.1.0/jars" />
78+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/8.1.0/jars" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/8.1.0/jars" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appinvite/8.1.0/jars" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appstate/8.1.0/jars" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/8.1.0/jars" />
83+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.1.0/jars" />
84+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-cast/8.1.0/jars" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-drive/8.1.0/jars" />
86+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-fitness/8.1.0/jars" />
87+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-games/8.1.0/jars" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-gcm/8.1.0/jars" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-identity/8.1.0/jars" />
90+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-location/8.1.0/jars" />
91+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-maps/8.1.0/jars" />
92+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-measurement/8.1.0/jars" />
93+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-nearby/8.1.0/jars" />
94+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-panorama/8.1.0/jars" />
95+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-plus/8.1.0/jars" />
96+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-safetynet/8.1.0/jars" />
97+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-vision/8.1.0/jars" />
98+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-wallet/8.1.0/jars" />
99+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-wearable/8.1.0/jars" />
100+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services/8.1.0/jars" />
99101
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.larswerkman/HoloColorPicker/1.4/jars" />
100102
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
101103
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
@@ -114,36 +116,39 @@
114116
</content>
115117
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
116118
<orderEntry type="sourceFolder" forTests="false" />
117-
<orderEntry type="library" exported="" name="play-services-vision-7.8.0" level="project" />
118-
<orderEntry type="library" exported="" name="play-services-identity-7.8.0" level="project" />
119-
<orderEntry type="library" exported="" name="play-services-drive-7.8.0" level="project" />
120-
<orderEntry type="library" exported="" name="play-services-location-7.8.0" level="project" />
121-
<orderEntry type="library" exported="" name="support-v4-23.0.0" level="project" />
122-
<orderEntry type="library" exported="" name="play-services-nearby-7.8.0" level="project" />
123-
<orderEntry type="library" exported="" name="play-services-ads-7.8.0" level="project" />
124-
<orderEntry type="library" exported="" name="play-services-panorama-7.8.0" level="project" />
125119
<orderEntry type="library" exported="" name="mediarouter-v7-22.2.0" level="project" />
126-
<orderEntry type="library" exported="" name="play-services-safetynet-7.8.0" level="project" />
127-
<orderEntry type="library" exported="" name="play-services-analytics-7.8.0" level="project" />
128-
<orderEntry type="library" exported="" name="play-services-base-7.8.0" level="project" />
129-
<orderEntry type="library" exported="" name="play-services-appinvite-7.8.0" level="project" />
130-
<orderEntry type="library" exported="" name="play-services-plus-7.8.0" level="project" />
131-
<orderEntry type="library" exported="" name="play-services-7.8.0" level="project" />
132120
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
133-
<orderEntry type="library" exported="" name="play-services-appindexing-7.8.0" level="project" />
134-
<orderEntry type="library" exported="" name="HoloColorPicker-1.4" level="project" />
135-
<orderEntry type="library" exported="" name="play-services-fitness-7.8.0" level="project" />
136-
<orderEntry type="library" exported="" name="play-services-gcm-7.8.0" level="project" />
137-
<orderEntry type="library" exported="" name="play-services-games-7.8.0" level="project" />
138-
<orderEntry type="library" exported="" name="play-services-cast-7.8.0" level="project" />
139-
<orderEntry type="library" exported="" name="play-services-wearable-7.8.0" level="project" />
140-
<orderEntry type="library" exported="" name="play-services-wallet-7.8.0" level="project" />
141-
<orderEntry type="library" exported="" name="play-services-appstate-7.8.0" level="project" />
121+
<orderEntry type="library" exported="" name="play-services-measurement-8.1.0" level="project" />
122+
<orderEntry type="library" exported="" name="play-services-appindexing-8.1.0" level="project" />
123+
<orderEntry type="library" exported="" name="play-services-base-8.1.0" level="project" />
124+
<orderEntry type="library" exported="" name="play-services-location-8.1.0" level="project" />
125+
<orderEntry type="library" exported="" name="play-services-identity-8.1.0" level="project" />
126+
<orderEntry type="library" exported="" name="play-services-vision-8.1.0" level="project" />
142127
<orderEntry type="library" exported="" name="org.eclipse.paho.client.mqttv3-1.0.2" level="project" />
143-
<orderEntry type="library" exported="" name="appcompat-v7-23.0.0" level="project" />
144-
<orderEntry type="library" exported="" name="support-annotations-23.0.0" level="project" />
128+
<orderEntry type="library" exported="" name="play-services-drive-8.1.0" level="project" />
129+
<orderEntry type="library" exported="" name="play-services-analytics-8.1.0" level="project" />
130+
<orderEntry type="library" exported="" name="play-services-8.1.0" level="project" />
131+
<orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
132+
<orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
133+
<orderEntry type="library" exported="" name="play-services-cast-8.1.0" level="project" />
134+
<orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
135+
<orderEntry type="library" exported="" name="play-services-appinvite-8.1.0" level="project" />
136+
<orderEntry type="library" exported="" name="play-services-ads-8.1.0" level="project" />
137+
<orderEntry type="library" exported="" name="play-services-appstate-8.1.0" level="project" />
138+
<orderEntry type="library" exported="" name="play-services-gcm-8.1.0" level="project" />
139+
<orderEntry type="library" exported="" name="HoloColorPicker-1.4" level="project" />
140+
<orderEntry type="library" exported="" name="play-services-safetynet-8.1.0" level="project" />
141+
<orderEntry type="library" exported="" name="play-services-games-8.1.0" level="project" />
142+
<orderEntry type="library" exported="" name="play-services-wallet-8.1.0" level="project" />
143+
<orderEntry type="library" exported="" name="play-services-basement-8.1.0" level="project" />
144+
<orderEntry type="library" exported="" name="play-services-maps-8.1.0" level="project" />
145+
<orderEntry type="library" exported="" name="play-services-nearby-8.1.0" level="project" />
146+
<orderEntry type="library" exported="" name="play-services-panorama-8.1.0" level="project" />
147+
<orderEntry type="library" exported="" name="play-services-fitness-8.1.0" level="project" />
145148
<orderEntry type="library" exported="" name="org.eclipse.paho.android.service-1.0.2" level="project" />
146-
<orderEntry type="library" exported="" name="play-services-maps-7.8.0" level="project" />
149+
<orderEntry type="library" exported="" name="play-services-wearable-8.1.0" level="project" />
150+
<orderEntry type="library" exported="" name="play-services-plus-8.1.0" level="project" />
147151
<orderEntry type="module" module-name="dFULibrary" exported="" />
152+
<orderEntry type="library" exported="" name="org.apache.http.legacy-android-23" level="project" />
148153
</component>
149154
</module>

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 23
5-
buildToolsVersion "23.0.0"
5+
buildToolsVersion "23.0.2"
66

77
defaultConfig {
88
applicationId "com.adafruit.bluefruit.le.connect"
99
minSdkVersion 19
1010
targetSdkVersion 22
11-
versionCode 6
11+
versionCode 7
1212
versionName "1.1.4"
1313
}
1414
buildTypes {
@@ -29,8 +29,8 @@ repositories {
2929

3030
dependencies {
3131
compile fileTree(dir: 'libs', include: ['*.jar'])
32-
compile 'com.android.support:appcompat-v7:23.0.0'
33-
compile 'com.google.android.gms:play-services:7.8.0'
32+
compile 'com.android.support:appcompat-v7:23.1.0'
33+
compile 'com.google.android.gms:play-services:8.1.0'
3434
compile 'com.larswerkman:HoloColorPicker:1.4'
3535
compile project(":dFULibrary")
3636
compile(group: 'org.eclipse.paho', name: 'org.eclipse.paho.android.service', version: '1.0.2') {

app/src/main/java/com/adafruit/bluefruit/le/connect/app/MainActivity.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
import android.content.DialogInterface;
1313
import android.content.Intent;
1414
import android.content.SharedPreferences;
15+
import android.os.Build;
1516
import android.os.Bundle;
1617
import android.os.SystemClock;
1718
import android.preference.PreferenceManager;
19+
import android.provider.Settings;
1820
import android.support.v4.widget.SwipeRefreshLayout;
1921
import android.support.v7.app.AppCompatActivity;
2022
import android.util.Log;
@@ -162,9 +164,10 @@ public void run() {
162164

163165
// Check if bluetooth adapter is available
164166
final boolean wasBluetoothEnabled = manageBluetoothAvailability();
167+
final boolean areLocationServicesReadyForScanning = manageLocationServiceAvailabiltyForScanning();
165168

166169
// Reset bluetooth
167-
if (autoResetBluetoothOnStart && wasBluetoothEnabled) {
170+
if (autoResetBluetoothOnStart && wasBluetoothEnabled && areLocationServicesReadyForScanning) {
168171
BleUtils.resetBluetoothAdapter(this, this);
169172
}
170173
}
@@ -360,7 +363,7 @@ private boolean manageBluetoothAvailability() {
360363
}
361364
case BleUtils.STATUS_BLUETOOTH_DISABLED: {
362365
isEnabled = false; // it was already off
363-
// if no enabled, launch settings dialog to enableNotification it (user should always be prompted before automatically enabling bluetooth)
366+
// if no enabled, launch settings dialog to enable it (user should always be prompted before automatically enabling bluetooth)
364367
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
365368
startActivityForResult(enableBtIntent, kActivityRequestCode_EnableBluetooth);
366369
// execution will continue at onActivityResult()
@@ -377,6 +380,32 @@ private boolean manageBluetoothAvailability() {
377380
return isEnabled;
378381
}
379382

383+
private boolean manageLocationServiceAvailabiltyForScanning() {
384+
385+
boolean areLocationServiceReady = true;
386+
387+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Location services are only needed to be enabled from Android 6.0
388+
int locationMode = Settings.Secure.LOCATION_MODE_OFF;
389+
try {
390+
locationMode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE);
391+
392+
} catch (Settings.SettingNotFoundException e) {
393+
e.printStackTrace();
394+
}
395+
areLocationServiceReady = locationMode != Settings.Secure.LOCATION_MODE_OFF;
396+
397+
if (!areLocationServiceReady) {
398+
399+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
400+
builder.setMessage(R.string.dialog_error_nolocationservices_requiredforscan_marshmallow)
401+
.setPositiveButton(R.string.dialog_ok, null)
402+
.show();
403+
}
404+
}
405+
406+
return areLocationServiceReady;
407+
}
408+
380409
private void connect(BluetoothDevice device) {
381410
boolean isConnecting = mBleManager.connect(this, device.getAddress());
382411
if (isConnecting) {

app/src/main/java/com/adafruit/bluefruit/le/connect/ble/BleDevicesScanner.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class BleDevicesScanner {
2626
private List<UUID> mServicesToDiscover;
2727
private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
2828
private final LeScansPoster mLeScansPoster;
29-
private int mScanSession = 0;
3029

3130
//
3231
private BluetoothAdapter.LeScanCallback mLeScanCallback =
@@ -60,7 +59,6 @@ public void run() {
6059
if (mIsScanning) {
6160
Log.d(TAG, "Scan timer expired. Restart scan");
6261
stop();
63-
mScanSession++;
6462
start();
6563
}
6664
}

app/src/main/java/com/adafruit/bluefruit/le/connect/ble/BleGattExecutor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,19 @@ public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
289289
};
290290
}
291291

292-
public static interface BleExecutorListener {
292+
public interface BleExecutorListener {
293293

294-
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState);
294+
void onConnectionStateChange(BluetoothGatt gatt, int status, int newState);
295295

296-
public void onServicesDiscovered(BluetoothGatt gatt, int status);
296+
void onServicesDiscovered(BluetoothGatt gatt, int status);
297297

298-
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status);
298+
void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status);
299299

300-
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic);
300+
void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic);
301301

302-
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status);
302+
void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status);
303303

304-
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status);
304+
void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status);
305305

306306
}
307307
}

0 commit comments

Comments
 (0)