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?
Asked
Active
Viewed 712 times
0
-
Guy, try to do like this post. http://stackoverflow.com/questions/9913645/android-enable-usb-tethering-programmatically-there-is-an-app-that-did-it-fo – ealvess Aug 17 '14 at 13:46
-
It works only in 2.3 and it does not work above 4.0 – user1000703 Aug 17 '14 at 13:59
1 Answers
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