首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android在AOSP中编程启用Usb Tethering

Android在AOSP中编程启用Usb Tethering
EN

Stack Overflow用户
提问于 2014-08-17 21:34:32
回答 1查看 642关注 0票数 0

我正在开发Android应用程序。我需要在连接Usb时以编程方式启用Usb tethering。由于android的安全性,我不能在4.4版本中做到这一点。所以我下载了Android4.4的源代码,在it.can上做了一些修改,有人能指导我怎么做吗?

EN

回答 1

Stack Overflow用户

发布于 2014-11-24 14:30:33

以下代码可以在4.0、4.1、4.2版本中正常运行,但在4.3和4.4版本中无法正常运行

代码语言:javascript
复制
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();
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25349659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档