以编程方式启用USB共享网络-有一个应用程序针对2.3 [英] Enabling USB tethering programmatically - there is an app that did it for 2.3

查看:68
本文介绍了以编程方式启用USB共享网络-有一个应用程序针对2.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里已经阅读了很多关于SO的问题,这些问题询问如何以编程方式启用USB网络共享.

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 system apps.

但对于2.3,您可以在市场上下载适合您的应用.

Yet for 2.3 you could download an app in the market that would do it for you.

https://play.google.com/store/apps/details?id = org.tdtran.autousbtethering

在ICS(Android 4.0.3)上,它不再起作用.

On ICS (Android 4.0.3) it no longer works.

对于2.3,他们是如何做到的? 4.0也可能吗?

How did they do it for 2.3? Is it possible also for 4.0?

推荐答案

使用以下代码,您可以启用USB绑定.我没有在4.0中进行测试.

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();
                        }
                    }
                }
        }

这篇关于以编程方式启用USB共享网络-有一个应用程序针对2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆