Compare commits
4
Commits
app_v1.1.0
...
app_v1.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8871fc5d20 | ||
|
|
e5ed6f1dbb | ||
|
|
e838cacad1 | ||
|
|
ebc44c7537 |
@@ -146,6 +146,8 @@ You can also lookup values and convert them to human friendly strings:
|
|||||||
* v1.1.0:
|
* v1.1.0:
|
||||||
* App refactor and materialisation.
|
* App refactor and materialisation.
|
||||||
* Added runtime permissions.
|
* Added runtime permissions.
|
||||||
|
* v1.1.1:
|
||||||
|
* Fix for [issue 23](https://github.com/alt236/Bluetooth-LE-Library---Android/issues/23)
|
||||||
|
|
||||||
## Permission Explanation
|
## Permission Explanation
|
||||||
You will need the following permissions to access the Bluetooth Hardware
|
You will need the following permissions to access the Bluetooth Hardware
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ apply plugin: 'com.android.application'
|
|||||||
|
|
||||||
final int versionMajor = 1
|
final int versionMajor = 1
|
||||||
final int versionMinor = 1
|
final int versionMinor = 1
|
||||||
final int versionPatch = 0
|
final int versionPatch = 1
|
||||||
final int androidVersionCode = 6
|
final int androidVersionCode = 7
|
||||||
|
|
||||||
final int targetSdk = rootProject.targetSdkVersion;
|
final int targetSdk = rootProject.targetSdkVersion;
|
||||||
final int minSdkRed = rootProject.minSdkVersion;
|
final int minSdkRed = rootProject.minSdkVersion;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package uk.co.alt236.btlescan.ui.main;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
@@ -119,22 +120,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_scan:
|
case R.id.menu_scan:
|
||||||
PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(this,
|
startScanPrepare();
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case R.id.menu_stop:
|
case R.id.menu_stop:
|
||||||
mScanner.scanLeDevice(-1, false);
|
mScanner.scanLeDevice(-1, false);
|
||||||
@@ -174,9 +160,36 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
invalidateOptionsMenu();
|
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() {
|
private void startScan() {
|
||||||
final boolean mIsBluetoothOn = mBluetoothUtils.isBluetoothOn();
|
final boolean isBluetoothOn = mBluetoothUtils.isBluetoothOn();
|
||||||
final boolean mIsBluetoothLePresent = mBluetoothUtils.isBluetoothLeSupported();
|
final boolean isBluetoothLePresent = mBluetoothUtils.isBluetoothLeSupported();
|
||||||
mDeviceStore.clear();
|
mDeviceStore.clear();
|
||||||
updateItemCount(0);
|
updateItemCount(0);
|
||||||
|
|
||||||
@@ -184,7 +197,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
mList.setAdapter(mRecyclerAdapter);
|
mList.setAdapter(mRecyclerAdapter);
|
||||||
|
|
||||||
mBluetoothUtils.askUserToEnableBluetoothIfNeeded();
|
mBluetoothUtils.askUserToEnableBluetoothIfNeeded();
|
||||||
if (mIsBluetoothOn && mIsBluetoothLePresent) {
|
if (isBluetoothOn && isBluetoothLePresent) {
|
||||||
mScanner.scanLeDevice(-1, true);
|
mScanner.scanLeDevice(-1, true);
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user