2016-08-10 14 views
0

私は、WiFiホットスポットの作成にWifiP2pManager.createGroup()Reference)を使用するたびに、完全に新しいネットワーク(新しいSSIDとパスワード)が作成されていることに気付きました。この新しいグループは永続グループとして保存されますが、私の場合は一度だけ使用されます。これは、WiFi Direct/WiFiのP2P設定を浪費する多くの「廃棄グループ」につながります。 WifiP2pGroup - 永続グループを再起動しますか?

There is a wayは非常にクリーン解決策になるつのグループのすべての時間を再利用すべての永続のWiFi P2Pグループが、を削除します。 実際には、このオプションは、ユーザーに提供されています:

Image

私はプログラム的にこれを使用するためにどのようにそれを把握することはできません...しかし、のかもしれないいくつかのあなたはことができます;)

ご協力いただきありがとうございます。

答えて

0

WiFi-Buddyはあなたにとって便利なライブラリです。 Javaリフレクションを使用してWi-Fi Direct APIのremovePersistentGroup()メソッドを呼び出すremovePersistentGroups()メソッドがあります。

/** 
* Removes persistent/remembered groups 
* 
* Source: https://android.googlesource.com/platform/cts/+/jb-mr1-dev%5E1%5E2..jb-mr1-dev%5E1/ 
* Author: Nick Kralevich <[email protected]> 
* 
* WifiP2pManager.java has a method deletePersistentGroup(), but it is not accessible in the 
* SDK. According to Vinit Deshpande <[email protected]>, it is a common Android paradigm to 
* expose certain APIs in the SDK and hide others. This allows Android to maintain stability and 
* security. As a workaround, this removePersistentGroups() method uses Java reflection to call 
* the hidden method. We can list all the methods in WifiP2pManager and invoke "deletePersistentGroup" 
* if it exists. This is used to remove all possible persistent/remembered groups. 
*/ 
private void removePersistentGroups() { 
    try { 
     Method[] methods = WifiP2pManager.class.getMethods(); 
     for (int i = 0; i < methods.length; i++) { 
      if (methods[i].getName().equals("deletePersistentGroup")) { 
       // Remove any persistent group 
       for (int netid = 0; netid < 32; netid++) { 
        methods[i].invoke(wifiP2pManager, channel, netid, null); 
       } 
      } 
     } 
     Log.i(TAG, "Persistent groups removed"); 
    } catch(Exception e) { 
     Log.e(TAG, "Failure removing persistent groups: " + e.getMessage()); 
     e.printStackTrace(); 
    } 
} 
+0

回答ありがとうございますが、私は_existing_グループを再起動するため、SSID /パスワード**はそのままです** – Candor

関連する問題