4 Commits

Author SHA1 Message Date
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
3 changed files with 36 additions and 21 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

@@ -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

@@ -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();
}