New to Bluetooth and BT APIs in android.

Trying to pair a bluetooth gamepad controller [HID profile] to my device 
programatically:

Tried reflections after going through code of the Setting app:

    //pairing
    public boolean createBond(BluetoothDevice btDevice)
            throws Exception
    {
        Class class1 = Class.forName("android.bluetooth.BluetoothDevice");
        Method createBondMethod = class1.getMethod("createBond");
        Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);
        return returnValue.booleanValue();
    }
    


----------


    //connecting   
    public boolean createBTConnection(BluetoothProfile proxy, 
BluetoothDevice btDevice)
    {
        Boolean returnValue = false;
        Class class1 = null;
        try {
            class1 = 
Class.forName("android.bluetooth.BluetoothInputDevice");
            Method createConnectionMethod = class1.getMethod("connect", new 
Class[] {BluetoothDevice.class});
            returnValue = (Boolean) createConnectionMethod.invoke(proxy, 
btDevice);
        } catch (...) {}
        return returnValue.booleanValue();
    }
    
    BluetoothProfile.ServiceListener mProfileListener = new 
BluetoothProfile.ServiceListener() {
        @Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) 
{
            //4 == BluetoothInputDevice
            if (profile == 4) {
                createBTConnection(proxy, btDevice);
                //doesnot connect ):
                ...
            }
        }

        @Override
        public void onServiceDisconnected(int profile) {
            ...
        }
    };


----------

    
Getting paired but not connected.

Any pointers appreciated.

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to