我正在开发Android应用程序。我需要在连接Usb时以编程方式启用Usb tethering。由于android的安全性,我不能在4.4版本中做到这一点。所以我下载了Android4.4的源代码,在it.can上做了一些修改,有人能指导我怎么做吗?
发布于 2014-11-24 14:30:33
以下代码可以在4.0、4.1、4.2版本中正常运行,但在4.3和4.4版本中无法正常运行
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();
}https://stackoverflow.com/questions/25349659
复制相似问题