Android 为牛轧糖设置栓带/热点
我使用此代码激活或停用栓系热点,以便其他设备可以使用我设备的Internet数据。 它过去很管用,但牛轧糖已经不管用了,你有什么提示吗? 谢谢 这是我使用的代码:Android 为牛轧糖设置栓带/热点,android,android-7.0-nougat,tethering,Android,Android 7.0 Nougat,Tethering,我使用此代码激活或停用栓系热点,以便其他设备可以使用我设备的Internet数据。 它过去很管用,但牛轧糖已经不管用了,你有什么提示吗? 谢谢 这是我使用的代码: private boolean ActivateTethering(boolean bEstate) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); Method[] methods = wifi
private boolean ActivateTethering(boolean bEstate)
{ WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] methods = wifiManager.getClass().getDeclaredMethods();
for(Method method : methods)
{ if(method.getName().equals("setWifiApEnabled"))
{ try
{ if(bEstate == true)
{ wifiManager.setWifiEnabled(false); //Turning off wifi because tethering requires wifi to be off
method.invoke(wifiManager, null, true); //Activating tethering
return true;
}
else
{ method.invoke(wifiManager, null, false); //Deactivating tethering
return true;
}
}
catch(Exception e)
{ return false;
}
}
}
//Error setWifiApEnabled not found
return false;
}
我得到错误java.lang.reflect.InvocationTargetException请改用这个
try {
Method method = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
method.invoke(wifiManager, null, true); // true to enable, false to disable
} catch (NoSuchMethodException e) {
// WiFi tethering is blocked.
}
根据你的需要改变它
它在我的S7边缘工作,而getDeclaredMethods()代码>方式不正确