Skip to content

Commit 554217c

Browse files
authored
Merge pull request #616 from HansKrywaa/fix-615
Fix Nullpointer Exception
2 parents de3c418 + cdfeee7 commit 554217c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/android/BluetoothLePlugin.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,16 +1006,16 @@ private void initializeAction(JSONArray args, CallbackContext callbackContext) {
10061006
}
10071007
}
10081008

1009-
1009+
10101010
/**
1011-
* Retrieves a minimal set of adapter details
1011+
* Retrieves a minimal set of adapter details
10121012
* (address, name, initialized state, enabled state, scanning state, discoverable state)
10131013
*/
1014-
private void getAdapterInfoAction(CallbackContext callbackContext) {
1015-
JSONObject returnObj = new JSONObject();
1014+
private void getAdapterInfoAction(CallbackContext callbackContext) {
1015+
JSONObject returnObj = new JSONObject();
10161016

10171017
// Not yet initialized
1018-
if (bluetoothAdapter == null) {
1018+
if (bluetoothAdapter == null) {
10191019
Activity activity = cordova.getActivity();
10201020
BluetoothManager bluetoothManager = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE);
10211021
BluetoothAdapter bluetoothAdapterTmp = bluetoothManager.getAdapter();
@@ -1030,7 +1030,7 @@ private void getAdapterInfoAction(CallbackContext callbackContext) {
10301030
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
10311031
pluginResult.setKeepCallback(true);
10321032
callbackContext.sendPluginResult(pluginResult);
1033-
return;
1033+
return;
10341034
} else {
10351035
// Already initialized, so use the bluetoothAdapter class property to get all the info
10361036
addProperty(returnObj, keyAddress, bluetoothAdapter.getAddress());
@@ -1041,10 +1041,10 @@ private void getAdapterInfoAction(CallbackContext callbackContext) {
10411041
addProperty(returnObj, keyIsDiscoverable, bluetoothAdapter.getScanMode() == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
10421042
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);
10431043
pluginResult.setKeepCallback(true);
1044-
callbackContext.sendPluginResult(pluginResult);
1044+
callbackContext.sendPluginResult(pluginResult);
10451045
return;
10461046
}
1047-
1047+
10481048
}
10491049

10501050
private void enableAction(CallbackContext callbackContext) {
@@ -1690,7 +1690,7 @@ private boolean refreshDeviceCache(BluetoothGatt gatt) {
16901690
boolean bool = ((Boolean) localMethod.invoke(localBluetoothGatt, new Object[0])).booleanValue();
16911691
return bool;
16921692
}
1693-
}
1693+
}
16941694
catch (Exception localException) {
16951695
Log.e("BLE", "An exception occured while refreshing device cache");
16961696
}
@@ -2795,7 +2795,7 @@ public void onReceive(Context context, Intent intent) {
27952795

27962796
break;
27972797
case BluetoothAdapter.STATE_TURNING_OFF:
2798-
gattServer.close();
2798+
if(gattServer != null) gattServer.close();
27992799
break;
28002800
case BluetoothAdapter.STATE_ON:
28012801

0 commit comments

Comments
 (0)