@@ -492,6 +492,13 @@ public void run() {
492492 }
493493 });
494494 return true ;
495+ } else if ("wasConnected" .equals (action )) {
496+ cordova .getThreadPool ().execute (new Runnable () {
497+ public void run () {
498+ wasConnectedAction (args ,callbackContext );
499+ }
500+ });
501+ return true ;
495502 } else if (isConnectedActionName .equals (action )) {
496503 cordova .getThreadPool ().execute (new Runnable () {
497504 public void run () {
@@ -2427,6 +2434,47 @@ private void isScanningAction(CallbackContext callbackContext) {
24272434 callbackContext .success (returnObj );
24282435 }
24292436
2437+ private void wasConnectedAction (JSONArray args , CallbackContext callbackContext ) {
2438+ if (isNotInitialized (callbackContext , true )) {
2439+ return ;
2440+ }
2441+
2442+ JSONObject obj = getArgsObject (args );
2443+ if (isNotArgsObject (obj , callbackContext )) {
2444+ return ;
2445+ }
2446+
2447+ String address = getAddress (obj );
2448+ if (isNotAddress (address , callbackContext )) {
2449+ return ;
2450+ }
2451+
2452+ HashMap <Object , Object > connection = connections .get (address );
2453+ if (connection == null ) {
2454+ JSONObject returnObj = new JSONObject ();
2455+
2456+ addProperty (returnObj , "wasConnected" , false );
2457+
2458+ addProperty (returnObj , keyAddress , address );
2459+
2460+ callbackContext .success (returnObj );
2461+
2462+ return ;
2463+ }
2464+
2465+ BluetoothGatt bluetoothGatt = (BluetoothGatt )connection .get (keyPeripheral );
2466+
2467+ BluetoothDevice device = bluetoothGatt .getDevice ();
2468+
2469+ JSONObject returnObj = new JSONObject ();
2470+
2471+ addProperty (returnObj , "wasConnected" , true );
2472+
2473+ addDevice (returnObj , device );
2474+
2475+ callbackContext .success (returnObj );
2476+ }
2477+
24302478 private void isConnectedAction (JSONArray args , CallbackContext callbackContext ) {
24312479 if (isNotInitialized (callbackContext , true )) {
24322480 return ;
0 commit comments