我正在开发 Android 应用程序。连接 USB 时,我需要以编程方式启用 USB 网络共享。由于 android 安全性,我无法在 4.4 版本中执行此操作。所以我下载了 android 4.4 源代码对其进行了一些更改。谁能指导我怎么做?
问问题
651 次
1 回答
0
下面的代码在 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();
}
于 2014-11-24T06:30:32.787 回答