Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows the plugin to connect Android to Android #360

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/android/com/megster/cordova/BluetoothSerial.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions src/android/com/megster/cordova/BluetoothSerialService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//
Expand Down Expand Up @@ -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);
Expand Down