Enabling USB tethering programmatically - there is an app that did it for 2.3

前端 未结 6 1846
野趣味
野趣味 2020-12-05 12:15

I\'ve read many questions here on SO that ask how to enable USB tethering programmatically.

The answer is always the same, ordinary applications can\'t do it, only s

6条回答
  •  温柔的废话
    2020-12-05 13:21

    using the following code you can enable USB tethering. i didt test in 4.0.

     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 e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IllegalAccessException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (InvocationTargetException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
            }
    

提交回复
热议问题