set Pin for Bluetooth device - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

set Pin for Bluetooth device

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

import android.bluetooth.BluetoothDevice;
import android.util.Log;

public class Main {
    static public boolean setPin(Class btClass, BluetoothDevice btDevice,
            String str) throws Exception {
        try {//  ww  w. j  a v a2 s .  c  om
            Method removeBondMethod = btClass.getDeclaredMethod("setPin",
                    new Class[] { byte[].class });
            Boolean returnValue = (Boolean) removeBondMethod.invoke(
                    btDevice, new Object[] { str.getBytes() });
            Log.e("returnValue", "" + returnValue);
        } catch (SecurityException e) {
            // throw new RuntimeException(e.getMessage());
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // throw new RuntimeException(e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return true;
    }
}

Related Tutorials