connect to Bluetooth device - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

connect to Bluetooth device

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

import android.bluetooth.BluetoothDevice;

import android.util.Log;

public class Main {
    @SuppressWarnings({ "unchecked", "rawtypes", "unused" })
    public static Boolean connect(BluetoothDevice bdDevice) {
        Boolean bool = false;/* w  w  w. j av a  2s .  com*/
        try {
            Log.i("Log", "service metohd is called ");
            Class cl = Class.forName("android.bluetooth.BluetoothDevice");
            Class[] par = {};
            Method method = cl.getMethod("createBond", par);
            Object[] args = {};
            bool = (Boolean) method.invoke(bdDevice);//, args);// this invoke creates the detected devices paired.
            //Log.i("Log", "This is: "+bool.booleanValue());
            //Log.i("Log", "devicesss: "+bdDevice.getName());
        } catch (Exception e) {
            Log.i("Log", "Inside catch of serviceFromDevice Method");
            e.printStackTrace();
        }
        return bool.booleanValue();
    }
}

Related Tutorials