[英]Android enable Usb Tethering programatically in AOSP
我正在開發Android應用程序。 連接USB時,我需要以編程方式啟用USB共享網絡。 由於Android安全性,我無法在4.4版本中執行此操作。 所以我下載了android 4.4源代碼進行一些更改。有人可以指導我怎么做嗎?
下面的代碼在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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.