RS enable BT before scanning
This commit is contained in:
parent
70f4b72ff9
commit
c33dd1e7d7
1 changed files with 10 additions and 15 deletions
|
@ -7,8 +7,10 @@ import android.bluetooth.le.BluetoothLeScanner;
|
||||||
import android.bluetooth.le.ScanCallback;
|
import android.bluetooth.le.ScanCallback;
|
||||||
import android.bluetooth.le.ScanResult;
|
import android.bluetooth.le.ScanResult;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -31,7 +33,6 @@ import info.nightscout.utils.SP;
|
||||||
public class BLEScanActivity extends AppCompatActivity {
|
public class BLEScanActivity extends AppCompatActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(BLEScanActivity.class);
|
private static Logger log = LoggerFactory.getLogger(BLEScanActivity.class);
|
||||||
|
|
||||||
private Context mContext = null;
|
|
||||||
|
|
||||||
private ListView listView = null;
|
private ListView listView = null;
|
||||||
private ListAdapter mListAdapter = null;
|
private ListAdapter mListAdapter = null;
|
||||||
|
@ -53,26 +54,20 @@ public class BLEScanActivity extends AppCompatActivity {
|
||||||
listView.setEmptyView(findViewById(R.id.danars_blescanner_nodevice));
|
listView.setEmptyView(findViewById(R.id.danars_blescanner_nodevice));
|
||||||
listView.setAdapter(mListAdapter);
|
listView.setAdapter(mListAdapter);
|
||||||
|
|
||||||
initView();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initView() {
|
|
||||||
mContext = getApplicationContext();
|
|
||||||
|
|
||||||
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
|
|
||||||
mBluetoothAdapter = bluetoothManager.getAdapter();
|
|
||||||
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
|
|
||||||
|
|
||||||
// MIKE: test mBluetoothLeScanner for null (bt disabled)
|
|
||||||
|
|
||||||
mListAdapter.notifyDataSetChanged();
|
mListAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
|
||||||
|
|
||||||
|
if (mBluetoothLeScanner == null) {
|
||||||
|
mBluetoothAdapter.enable();
|
||||||
|
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
|
||||||
|
}
|
||||||
startScan();
|
startScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +133,7 @@ public class BLEScanActivity extends AppCompatActivity {
|
||||||
ViewHolder holder;
|
ViewHolder holder;
|
||||||
|
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
v = View.inflate(mContext, R.layout.danars_blescanner_item, null);
|
v = View.inflate(getApplicationContext(), R.layout.danars_blescanner_item, null);
|
||||||
holder = new ViewHolder(v);
|
holder = new ViewHolder(v);
|
||||||
v.setTag(holder);
|
v.setTag(holder);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue