5 Commits

Author SHA1 Message Date
40a181cc3e Optional refresh call through reflection
Add a method to call refresh on GATT through reflection and set
auto-reconnect to true.
2017-03-13 15:19:43 +00:00
Alexandros Schillings
8871fc5d20 Merge pull request #25 from alt236/release/app_v1_1_1
Preparing for App relase v1.1.1
2017-02-03 12:32:30 +00:00
Alexandros Schillings
e5ed6f1dbb Preparing for App relase v1.1.1 2017-02-03 12:16:08 +00:00
Alexandros Schillings
e838cacad1 Merge pull request #24 from alt236/bugfix/dont-ask-for-location-permission-pre-API23
App no longer tries to ask for COARSE_LOCATION permission pre API 23 …
2017-02-03 12:12:48 +00:00
Alexandros Schillings
ebc44c7537 App no longer tries to ask for COARSE_LOCATION permission pre API 23 as it is not needed 2017-02-03 12:09:20 +00:00
6 changed files with 66 additions and 33 deletions

View File

@@ -146,6 +146,8 @@ You can also lookup values and convert them to human friendly strings:
* v1.1.0:
* App refactor and materialisation.
* Added runtime permissions.
* v1.1.1:
* Fix for [issue 23](https://github.com/alt236/Bluetooth-LE-Library---Android/issues/23)
## Permission Explanation
You will need the following permissions to access the Bluetooth Hardware

View File

@@ -67,14 +67,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
@@ -83,7 +75,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
@@ -92,6 +91,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
@@ -106,5 +106,6 @@
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="mockito-core-1.9.5" level="project" />
<orderEntry type="library" exported="" name="android-android-24" level="project" />
</component>
</module>

View File

@@ -2,8 +2,8 @@ apply plugin: 'com.android.application'
final int versionMajor = 1
final int versionMinor = 1
final int versionPatch = 0
final int androidVersionCode = 6
final int versionPatch = 1
final int androidVersionCode = 7
final int targetSdk = rootProject.targetSdkVersion;
final int minSdkRed = rootProject.minSdkVersion;

View File

@@ -85,7 +85,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.2.0/jars" />
@@ -104,10 +103,10 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
@@ -138,6 +137,7 @@
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="easycursor-android-1.0.0" level="project" />
<orderEntry type="module" module-name="library" exported="" />
<orderEntry type="library" exported="" name="android-android-24" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="objenesis-1.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="mockito-core-1.9.5" level="project" />
</component>

View File

@@ -31,6 +31,7 @@ import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import java.lang.reflect.Method;
import java.util.List;
/**
@@ -176,7 +177,8 @@ public class BluetoothLeService extends Service {
// parameter to false.
Log.d(TAG, "Trying to create a new connection.");
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
mBluetoothGatt = device.connectGatt(this, true, mGattCallback);
//boolean v = refreshDeviceCache(mBluetoothGatt);
mBluetoothDeviceAddress = address;
setConnectionState(State.CONNECTING, true);
retVal = true;
@@ -186,6 +188,21 @@ public class BluetoothLeService extends Service {
return retVal;
}
private boolean refreshDeviceCache(BluetoothGatt gatt){
try {
BluetoothGatt localBluetoothGatt = gatt;
Method localMethod = localBluetoothGatt.getClass().getMethod("refresh", new Class[0]);
if (localMethod != null) {
boolean bool = ((Boolean) localMethod.invoke(localBluetoothGatt, new Object[0])).booleanValue();
return bool;
}
}
catch (Exception localException) {
Log.e(TAG, "An exception occured while refreshing device");
}
return false;
}
private synchronized void setConnectionState(final State newState, final boolean broadCast) {
Log.i(TAG, "Setting internal state to " + newState);
mConnectionState = newState;

View File

@@ -3,6 +3,7 @@ package uk.co.alt236.btlescan.ui.main;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
@@ -119,22 +120,7 @@ public class MainActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_scan:
PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, new PermissionsResultAction() {
@Override
public void onGranted() {
startScan();
}
@Override
public void onDenied(String permission) {
Toast.makeText(MainActivity.this,
R.string.permission_not_granted_coarse_location,
Toast.LENGTH_SHORT)
.show();
}
});
startScanPrepare();
break;
case R.id.menu_stop:
mScanner.scanLeDevice(-1, false);
@@ -174,9 +160,36 @@ public class MainActivity extends AppCompatActivity {
invalidateOptionsMenu();
}
private void startScanPrepare() {
//
// The COARSE_LOCATION permission is only needed after API 23 to do a BTLE scan
//
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, new PermissionsResultAction() {
@Override
public void onGranted() {
startScan();
}
@Override
public void onDenied(String permission) {
Toast.makeText(MainActivity.this,
R.string.permission_not_granted_coarse_location,
Toast.LENGTH_SHORT)
.show();
}
});
} else {
startScan();
}
}
private void startScan() {
final boolean mIsBluetoothOn = mBluetoothUtils.isBluetoothOn();
final boolean mIsBluetoothLePresent = mBluetoothUtils.isBluetoothLeSupported();
final boolean isBluetoothOn = mBluetoothUtils.isBluetoothOn();
final boolean isBluetoothLePresent = mBluetoothUtils.isBluetoothLeSupported();
mDeviceStore.clear();
updateItemCount(0);
@@ -184,7 +197,7 @@ public class MainActivity extends AppCompatActivity {
mList.setAdapter(mRecyclerAdapter);
mBluetoothUtils.askUserToEnableBluetoothIfNeeded();
if (mIsBluetoothOn && mIsBluetoothLePresent) {
if (isBluetoothOn && isBluetoothLePresent) {
mScanner.scanLeDevice(-1, true);
invalidateOptionsMenu();
}