0

I am developing Android application. I need to enable Usb tethering programatically when Usb is connected. Due to android security i am not able to do it in 4.4 version. So i downloaded android 4.4 source code to make some changes on it.can anyone guide me how to do it?

1 Answers1

0

the code below can work well in 4.0, 4.1, 4.2, version ,but can't work well in 4.3 and 4.4 version

try {  


            Class<?> classBluetoothPan = Class.forName(sClassName);

            Constructor<?> ctor = classBluetoothPan.getDeclaredConstructor(Context.class, BluetoothProfile.ServiceListener.class);
            ctor.setAccessible(true);
            //Object instance = ctor.newInstance(getApplicationContext(), new BTPanServiceListener(getApplicationContext()));                 
            Object instance = ctor.newInstance(this, new BTPanServiceListener(this));
            //  Set Tethering ON
            Class[] paramSet = new Class[1];
            paramSet[0] = boolean.class;

            Method setTetheringOn = classBluetoothPan.getMethod("setBluetoothTethering", paramSet);
            //Method setTetheringOn = classBluetoothPan.getDeclaredMethod("setBluetoothTethering", paramSet);

            setTetheringOn.invoke(instance,true);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
yob
  • 1