切换无线网络共享编程中的Andr​​oid 4.2 [英] Toggle wifi tethering programmatically in Android 4.2

查看:133
本文介绍了切换无线网络共享编程中的Andr​​oid 4.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能切换无线网络共享中的Andr​​oid 4.2?我尝试<一href="http://stackoverflow.com/questions/3531801/enable-disable-usb-or-wifi-tethering-programmatically-on-android">this但似乎,它并没有使用Android的工作4.2!

Is there any possibility to toggle wifi tethering in Android 4.2? I tried this but it seems that it doesn't work using Android 4.2!

在此先感谢!

编辑:它的工作,我只是忘了设置正确的权限。有没有还的方法来检查其是否已经启用,这样我可以把它作为一个切换?

It DOES work I only forgot to set the right permission. Is there also a way to check if its already enabled so that I can use it as a toggle?

推荐答案

您应该能够做到这一点在安卓4.2请确保您有权限

You should be able to do it in Android 4.2 make sure you have the permission

android.permission.CHANGE_WIFI_STATE

和我们帮不了你,除非你发表您的code。

and we cannot help you unless you post your code.

我相信这将帮助你检查网络共享处于活动状态

I believe this will help you check if tethering is active

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
for(Method method: wmMethods){
  if(method.getName().equals("isWifiApEnabled")) {

try {
  method.invoke(wifi);
} catch (IllegalArgumentException e) {
  e.printStackTrace();
} catch (IllegalAccessException e) {
  e.printStackTrace();
} catch (InvocationTargetException e) {
  e.printStackTrace();
    }
  }
}

这篇关于切换无线网络共享编程中的Andr​​oid 4.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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