2012-04-04 5 views
5

の詳細設定を設定するには:は、どのように私は次のコードでONポータブルWiFiホットスポットを回してるアンドロイドwifihotspot

それは私の作品
private void createWifiAccessPoint() { 
    WifiManager wifiManager = (WifiManager)getBaseContext().getSystemService(Context.WIFI_SERVICE); 
    if(wifiManager.isWifiEnabled()) 
    { 
     wifiManager.setWifiEnabled(false);   
    }  
    Method[] wmMethods = wifiManager.getClass().getDeclaredMethods(); //Get all declared methods in WifiManager class  
    boolean methodFound=false; 
    for(Method method: wmMethods){ 
     if(method.getName().equals("setWifiApEnabled")){ 
      methodFound=true; 
      WifiConfiguration netConfig = new WifiConfiguration(); 
      netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); 
      netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); 
      netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); 
      netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); 
      netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); 
      netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); 
      netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); 
      netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); 
      try { 
       boolean apstatus=(Boolean) method.invoke(wifiManager, netConfig,true);   
       //statusView.setText("Creating a Wi-Fi Network \""+netConfig.SSID+"\""); 
       for (Method isWifiApEnabledmethod: wmMethods) 
       { 
        if(isWifiApEnabledmethod.getName().equals("isWifiApEnabled")){ 
         while(!(Boolean)isWifiApEnabledmethod.invoke(wifiManager)){ 
         }; 
         for(Method method1: wmMethods){ 
          if(method1.getName().equals("getWifiApState")){ 
           int apstate; 
           apstate=(Integer)method1.invoke(wifiManager); 
           //     netConfig=(WifiConfiguration)method1.invoke(wifi); 
           //statusView.append("\nSSID:"+netConfig.SSID+"\nPassword:"+netConfig.preSharedKey+"\n"); 
          } 
         } 
        } 
       } 
       if(apstatus) 
       { 
        System.out.println("SUCCESSdddd"); 
        //statusView.append("\nAccess Point Created!"); 
        //finish(); 
        //Intent searchSensorsIntent = new Intent(this,SearchSensors.class);    
        //startActivity(searchSensorsIntent); 
       }else 
       { 
        System.out.println("FAILED"); 
        //statusView.append("\nAccess Point Creation failed!"); 
       } 
      } catch (IllegalArgumentException e) { 
       e.printStackTrace(); 
      } catch (IllegalAccessException e) { 
       e.printStackTrace(); 
      } catch (InvocationTargetException e) { 
       e.printStackTrace(); 
      } 
     }  
    } 
    if(!methodFound){ 
     //statusView.setText("Your phone's API does not contain setWifiApEnabled method to configure an access point"); 
    } 
} 

は.......ホットスポットがオンになり......しかし、「メニュー」ボタンをクリックすることで高度な設定ができます....そしてここに問題があります... LanSettingsではDHCPが無効になり、電源モードはわずか5分で動作します....私はDHCPを有効にしてPowerMode - 「いつも」...どうすれば解決できますか?

+0

私は2.3.5を実行しているHTC電話機で全く同じ問題があります。あなたは解決策を見つけましたか? – Andy

答えて

1

これに対する答えを見つけるには、Androidのソースコードを調べなければならない場合があります。あなたのコードは、接続してIPアドレスを取得できるデバイスですか?その場合、APのDHCPが動作しています。

私は個人的には、ICS上でDHCP有効または無効のオプションやPowerModeを持っていません。

関連する問題