In case it's helpful, here's the relevant code:
https://github.com/piusvelte/RemoteAuthClient/blob/master/src/com/piusvelte/remoteauthclient/RemoteAuthClientService.java
public ConnectThread(String address, String state) {
mAddress = address;
mState = state;
BluetoothDevice device =
mBtAdapter.getRemoteDevice(mAddress);
BluetoothSocket tmp = null;
try {
// tmp =
device.createInsecureRfcommSocketToServiceRecord(sRemoteAuthServerUUID);
tmp =
device.createRfcommSocketToServiceRecord(sRemoteAuthServerUUID);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
mSocket = tmp;
}
public void run() {
if (mSocket == null) {
mMessage = "failed to get a socket";
mHandler.post(mRunnable);
} else {
if (!mSocket.isConnected()) {
if (mBtAdapter.isDiscovering())
mBtAdapter.cancelDiscovery();
try {
mSocket.connect();
} catch (IOException e) {
mMessage = "failed to connect";
mHandler.post(mRunnable);
shutdown();
return;
}
}
// Get the BluetoothSocket input and output
streams
try {
mInStream = mSocket.getInputStream();
mOutStream = mSocket.getOutputStream();
} catch (IOException e) {
mMessage = "failed to get streams";
mHandler.post(mRunnable);
shutdown();
return;
}
byte[] buffer = new byte[1024];
int readBytes = -1;
try {
readBytes = mInStream.read(buffer);
} catch (IOException e1) {
mMessage = "failed to read input
stream";
mHandler.post(mRunnable);
}
if (readBytes != -1) {
// construct a string from the valid
bytes in the buffer
String message = new String(buffer, 0,
readBytes);
// listen for challenge, then process a
response
if ((message.length() > 10) &&
(message.substring(0, 9).equals("challenge")))
mChallenge =
message.substring(10);
write(mState);
}
}
shutdown();
}
On Thursday, August 30, 2012 9:46:23 AM UTC-4, Bryan wrote:
>
> I've been trying to resolve a bluetooth connection problem between my app
> and service running on my laptop. I've paired my phone, a Nexus S 4G
> running AOSP 4.1.1, with my laptop through the System Settings. In my app,
> I'm unable to connect to my service over this pairing. However, if I go
> back into System Settings, Bluetooth Settings Activity, and select my
> laptop, the Bluetooth Settings Activity lists the laptop as selected and
> the Notification Bar icon for Bluetooth changes from grey to blue. Now, my
> app can connect just fine. If I disconnect from my laptop through the
> Bluetooth Settings Activity, my app can no longer connect. My understanding
> was that I only needed to be paired/bonded with a device to make a
> bluetooth connection. Why do I have to explicitly connect through the
> System/Bluetooth Settings before being able to connect in my app? I've
> tried both secure and insecure RfcommSocketToServiceRecord calls.
>
> Any help is greatly appreciated! Thank you!
>
> My source code is here:
>
> https://github.com/piusvelte/RemoteAuthClient
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en