diff --git a/README.md b/README.md index c30d9dad..18380deb 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # Bluetooth Serial Plugin for PhoneGap -This plugin enables serial communication over Bluetooth. It was written for communicating between Android or iOS and an Arduino. +This plugin enables serial communication over Bluetooth. It was written for communicating between Android(android to android and android to another device) or iOS and an Arduino. Android and Windows Phone use Classic Bluetooth. iOS uses Bluetooth Low Energy. +*This is a fork of the original Project with modifications(based on [tomvanenckevort fork](https://github.com/tomvanenckevort/BluetoothSerial)) that allow the connection between two android devices and tests using this [bluetooth printer emulator](https://play.google.com/store/apps/details?id=co.com.BluetoothPrinterEmulator) + ## Supported Platforms * Android @@ -17,7 +19,6 @@ Android and Windows Phone use Classic Bluetooth. iOS uses Bluetooth Low Energy. * The phone must initiate the Bluetooth connection * iOS Bluetooth Low Energy requires iPhone 4S, iPhone5, iPod 5, or iPad3+ - * Will *not* connect Android to Android[*](https://github.com/don/BluetoothSerial/issues/50#issuecomment-66405396) * Will *not* connect iOS to iOS[*](https://github.com/don/BluetoothSerial/issues/75#issuecomment-52591397) # Installing diff --git a/src/android/com/megster/cordova/BluetoothSerial.java b/src/android/com/megster/cordova/BluetoothSerial.java index 8be5575f..e9f36859 100644 --- a/src/android/com/megster/cordova/BluetoothSerial.java +++ b/src/android/com/megster/cordova/BluetoothSerial.java @@ -148,7 +148,9 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback delimiter = args.getString(0); dataAvailableCallback = callbackContext; - + //Start the Bluetooth service on the subscribe command to accept incoming connections. + bluetoothSerialService.start(); + PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); diff --git a/src/android/com/megster/cordova/BluetoothSerialService.java b/src/android/com/megster/cordova/BluetoothSerialService.java index 63ce6c53..4158c0f5 100644 --- a/src/android/com/megster/cordova/BluetoothSerialService.java +++ b/src/android/com/megster/cordova/BluetoothSerialService.java @@ -96,8 +96,9 @@ public synchronized void start() { // Cancel any thread currently running a connection if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;} - setState(STATE_NONE); - + //setState(STATE_NONE); + //Enabled listening state for accepting incoming connections. + setState(STATE_LISTEN); // Listen isn't working with Arduino. Ignore since assuming the phone will initiate the connection. // setState(STATE_LISTEN); // @@ -347,11 +348,11 @@ public ConnectThread(BluetoothDevice device, boolean secure) { // Get a BluetoothSocket for a connection with the given BluetoothDevice try { if (secure) { - // tmp = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE); - tmp = device.createRfcommSocketToServiceRecord(UUID_SPP); + tmp = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE); + //tmp = device.createRfcommSocketToServiceRecord(UUID_SPP); } else { - //tmp = device.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE); - tmp = device.createInsecureRfcommSocketToServiceRecord(UUID_SPP); + tmp = device.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE); + //tmp = device.createInsecureRfcommSocketToServiceRecord(UUID_SPP); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);