Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为牛轧糖设置栓带/热点_Android_Android 7.0 Nougat_Tethering - Fatal编程技术网

Android 为牛轧糖设置栓带/热点

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

我使用此代码激活或停用栓系热点,以便其他设备可以使用我设备的Internet数据。 它过去很管用,但牛轧糖已经不管用了,你有什么提示吗? 谢谢

这是我使用的代码:

  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()方式不正确