2016-08-10 1 views
0

WiFi 핫스팟을 만들기 위해 WifiP2pManager.createGroup() (Reference)을 사용할 때마다 새 네트워크 (새 SSID 및 비밀번호)이 작성되었음을 발견했습니다. 이 새로운 그룹은 내 경우에는 한 번만 사용되지만 영구 그룹으로 저장됩니다. 이것은 와이파이 다이렉트/와이파이 P2P 설정을 쓰레기로 버리는 많은 '쓰러 웨이 그룹'으로 이어진다. WifiP2pGroup - 영구 그룹을 다시 시작 하시겠습니까?

There is a way 훨씬 청소기 해결책이 될 것입니다 한 그룹의 모든 시간을 재사용 모든 영구 와이파이 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

답장을 보내 주셔서 감사합니다. 그러나 _ietisting_ 그룹을 다시 시작해야하므로 SSID/암호 **가 그대로 유지됩니다 ** – Candor

관련 문제