[英]How to enable Auto USB Tethering in Android programmatically or using shell for Android 7 and higher
I've tried different ways to do it:我尝试了不同的方法来做到这一点:
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
public void switchOnTethering() {
Object obj = getSystemService(Context.CONNECTIVITY_SERVICE);
for (Method m : obj.getClass().getDeclaredMethods()) {
if (m.getName().equals("tether")) {
try {
m.invoke(obj, "usb0");
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
adb shell
su
echo "rndis" > /sys/class/android_usb/android0/functions
echo "1" > /sys/class/android_usb/android0/enable
adb shell
su
netcfg rndis0 up
netcfg rndis0 dhcp
I need to make it for Android 7 and higher.我需要为 Android 7 及更高版本制作它。 It's okay if there is a way needs root because I have rooted device.
如果有办法需要 root 没关系,因为我有 root 设备。
In Android 7.0 it was adb shell svc usb setFunction rndis
在Android 7.0中是
adb shell svc usb setFunction rndis
You can also try adb shell setprop sys.usb.config rndis
您也可以尝试
adb shell setprop sys.usb.config rndis
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.