private boolean createBondApi18 ( @ NonNull final BluetoothDevice device ) { /* * There is a createBond() method in BluetoothDevice class but for now it's hidden. We will call it using reflections. It has been revealed in KitKat (Api19) */ try { final Method createBond = device . getClass ( ) . getMethod ( "createBond" ) ; mService . sendLogBroadcast ( DfuBaseService . LOG_LEVEL_DEBUG , "gatt.getDevice().createBond() (hidden)" ) ; return ( Boolean ) createBond . invoke ( device ) ; } catch ( final Exception e ) { Log . w ( TAG , "An exception occurred while creating bond" , e ) ; } return false ; }
A method that creates the bond to given device on API lower than Android 5 .