diff options
Diffstat (limited to 'app/src/main/java/com/javispedro/autobluetether/BtPanWrapper.java')
-rw-r--r-- | app/src/main/java/com/javispedro/autobluetether/BtPanWrapper.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/src/main/java/com/javispedro/autobluetether/BtPanWrapper.java b/app/src/main/java/com/javispedro/autobluetether/BtPanWrapper.java new file mode 100644 index 0000000..40cd84a --- /dev/null +++ b/app/src/main/java/com/javispedro/autobluetether/BtPanWrapper.java @@ -0,0 +1,39 @@ +package com.javispedro.autobluetether; + +import android.bluetooth.BluetoothProfile; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class BtPanWrapper { + private static final String CLASS_NAME = "android.bluetooth.BluetoothPan"; + public static final int PROFILE_ID = 5 /*BluetoothProfile.PAN*/; + private final BluetoothProfile p; + + public BtPanWrapper(BluetoothProfile pan) { + p = pan; + } + + private Object invoke(String methodName, Class[] parameterTypes, Object[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException { + Class c = Class.forName(CLASS_NAME); + Method m = c.getDeclaredMethod(methodName, parameterTypes); + return m.invoke(this.p, args); + } + + public boolean isTetheringOn() { + try { + return (boolean) invoke("isTetheringOn", null, null); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + public void setBluetoothTethering(boolean on) { + try { + invoke("setBluetoothTethering", new Class[] {Boolean.TYPE}, new Object[] {on}); + } catch (Exception e) { + e.printStackTrace(); + } + } +} |