Skip to content

Commit

Permalink
updates for adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajnoble committed Sep 25, 2016
1 parent cdb9bdc commit dcae3da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
Binary file modified library/blepdroid.jar
Binary file not shown.
56 changes: 22 additions & 34 deletions src/blepdroid/Blepdroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,25 @@ public void onResume() {
findParentIntention();
}

if (mBluetoothLeService != null) {
scanDevices();
} else {

PApplet.println(" mBluetoothLeService is null have to create mServiceConnection ");

Intent gattServiceIntent = new Intent(parent.getActivity(), BluetoothLeService.class);
parent.getActivity().bindService(gattServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);

PApplet.println(" ServiceConnection initialized?? ");

scanDevices();
}
// if (mBluetoothLeService != null) {
// scanDevices();
// } else {
//
// PApplet.println(" mBluetoothLeService is null have to create mServiceConnection ");
//
// Intent gattServiceIntent = new Intent(parent.getActivity(), BluetoothLeService.class);
// parent.getActivity().bindService(gattServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
//
// PApplet.println(" ServiceConnection initialized?? ");
//
// scanDevices();
// }

blepdroidAdapter = new BlepdroidAdapter(parent);

Intent gattServiceIntent = new Intent(parent.getActivity(), BluetoothLeService.class);
parent.getActivity().bindService(gattServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);

}
}

Expand Down Expand Up @@ -303,36 +309,18 @@ public void scanDevices() {
discoveredDevices.clear();

if (mHandler == null) {
mHandler = new Handler();
mHandler = parent.getActivity().getWindow().getDecorView().getHandler();
}

PApplet.println(" check functionality ");

// Use this check to determine whether BLE is supported on the device.
// Then you can
// selectively disable BLE-related features.
if (!parent.getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(Blepdroid.getInstance().parent.getActivity(), "BLE Not Supported", Toast.LENGTH_SHORT).show();
PApplet.println(" BLE Not Supported ");
// finish();
parent.exit();
}

// Initializes a Bluetooth adapter. For API level 18 and above, get a
// reference to
// BluetoothAdapter through BluetoothManager.
// final BluetoothManager bluetoothManager = (BluetoothManager) parent.getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
// mBluetoothAdapter = bluetoothManager.getAdapter();
//
// // Checks if Bluetooth is supported on the device.
// if (mBluetoothAdapter == null) {
// Toast.makeText(Blepdroid.getInstance().parent.getActivity(),"BLE Not Supported", Toast.LENGTH_SHORT).show();
// PApplet.println(" BLE Not Supported ");
// return;
// }

blepdroidAdapter = new BlepdroidAdapter(parent);

// scanLeDevice(true);
scanLeDevice(true);
}

public void writeCharacteristic(BlepdroidDevice device, UUID characteristic, byte[] data) {
Expand Down
7 changes: 3 additions & 4 deletions src/blepdroid/BlepdroidAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ public class BlepdroidAdapter {

parent = _parent;

final BluetoothManager bluetoothManager = (BluetoothManager) parent.getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();

if(sdkVersion < 22)
{

final BluetoothManager bluetoothManager = (BluetoothManager) parent.getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();

// Checks if Bluetooth is supported on the device.
if (mBluetoothAdapter == null) {
Toast.makeText(parent.getActivity(),"BLE Not Supported", Toast.LENGTH_SHORT).show();
Expand Down

0 comments on commit dcae3da

Please sign in to comment.