2017-03-13 3 views
1

このコードを使用してテザリングホットスポットを有効または無効にして、他のデバイスが自分のデバイスのインターネットデータを使用できるようにします。 それはうまく動作しましたが、それはヌーガットにとってはもう機能しません。何かヒントはありますか?ありがとう。 ヌガーのテザリング/ホットスポットの設定

これは私が使用するコードです:

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

答えて

0

利用代わりにこの

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. 
} 

あなたのニーズに合わせて変更し、それを得ます getDeclaredMethods();ウェイは私のS7エッジで動作しません。

関連する問題