public class BluetoothCompat { public static boolean createBondCompat(final BluetoothDevice device) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return device.createBond(); } else { Method method = device.getClass().getMethod("createBond", (Class[]) null); final Object invoke = method.invoke(device, (Object[]) null); return (Boolean) invoke; } } public static boolean removeBondCompat(final BluetoothDevice device) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method method = device.getClass().getMethod("removeBond", (Class[]) null); final Object invoke = method.invoke(device, (Object[]) null); return (Boolean) invoke; } private BluetoothCompat() { throw new AssertionError("No instances!"); } }