How I can enable USB Tethering programmatically on an Android 4.0 device?

后端 未结 2 1322
暖寄归人
暖寄归人 2020-12-14 20:05

I want to enable USB Tethering from my app on my Android 4.0 Device? The following code works for Android 2.2 but it does not work for 4.0. Can anyone help?

         


        
相关标签:
2条回答
  • 2020-12-14 20:44

    I've got code that is similar to this and it works on Android 4.0 (but only on some devices). Unfortunately, access to tethering is very vendor-specific. The one thing I did notice is that you don't make the method you are trying to call accessible. If, on the devices you are using, the method has been made private, this won't work. Try adding:

    method.setAccessible(true);
    

    before you call

    Integer code = (Integer) method.invoke(cm, "usb0");
    

    The other thing is that the interface name (in your case "usb0" is also vendor-specific. The interface name is different on different devices from different manufacturers. Make sure that you've got the correct interface name for the device you are testing.

    0 讨论(0)
  • 2020-12-14 20:54

    On my rooted device i got it working with this: (xamarin)

    suProcess = Runtime.GetRuntime().Exec("su root service call connectivity 30 i32 1");
    

    see https://android.stackexchange.com/questions/29954/can-i-change-some-android-settings-from-the-command-line

    0 讨论(0)
提交回复
热议问题