0

i am using code to make Bluetooth connection,

public void run() 
{
    try 
    {




        Method m = mBluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
        mBluetoothSocket = (BluetoothSocket) m.invoke(mBluetoothDevice, 1);


       // mBluetoothSocket = mBluetoothDevice.createRfcommSocketToServiceRecord(applicationUUID);
        mBluetoothAdapter.cancelDiscovery();

        mBluetoothSocket.connect();





    }
    catch (IOException eConnectException) 
    {
        Log.d(TAG, "CouldNotConnectToSocket", eConnectException);
         closeSocket(mBluetoothSocket);
         return;
    } catch (SecurityException e) {

        Log.d(TAG, "CouldNotConnectToSocket", e);
        closeSocket(mBluetoothSocket);
    } catch (NoSuchMethodException e) {

        Log.d(TAG, "CouldNotConnectToSocket", e);
        closeSocket(mBluetoothSocket);
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "CouldNotConnectToSocket", e);
        closeSocket(mBluetoothSocket);
    } catch (IllegalAccessException e) {
        Log.d(TAG, "CouldNotConnectToSocket", e);
        closeSocket(mBluetoothSocket);
    } catch (InvocationTargetException e) {
        Log.d(TAG, "CouldNotConnectToSocket", e);
        closeSocket(mBluetoothSocket);
    }
}

it is working fine on a Karbonn device which is android 2.2 and when i try same code on Samsung Galaxy Y and Sony Ericson Xperia mini then it does not work... What can be the issue..Kindly assist...

Sandeep
  • 2,573
  • 3
  • 21
  • 28

1 Answers1

0

Did u set the permissions in the manifest?

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>

And whats exactly your exception?

EDIT: according to this http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#ACTION_ACL_DISCONNECTED it's a low level exception that shouldnt occur.

How to programmatically tell if a Bluetooth device is connected? (Android 2.2) Does this help you?

Community
  • 1
  • 1
Thkru
  • 4,218
  • 2
  • 18
  • 37
  • these event i have already captured, main problem is that code is working fine on Karbon (2.2) but working on samsung galaxy y(2.3).. – Sandeep Apr 26 '12 at 12:40