'Wifi direct P2P aplication
I am trying to create a android Wi-Fi Direct (P2P) application. I found this code (Creating P2P Connections with Wi-Fi : Message passing issue) and I'm trying to test it, but when I run the application I can't even find the devices. I believe it is related to the API level (I already tried with 32 and 24) or Android.
When I debug this is what I find:
E/test: Discovering Peers Success..
D/OpenGLRenderer: HWUI Binary is enabled
D/OpenGLRenderer: HWUI Binary is enabled
E/test: NUMBER OF PEERS AVAILABLE: ----- 0
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
I/ViewRootImpl: jank_removeInvalidNode all the node in jank list is out of time
W/libEGL: EGLNativeWindowType 0x72f2a6d010 disconnect failed
V/AudioManager: playSoundEffect effectType: 0
V/AudioManager: querySoundEffectsEnabled...
D/WifiP2pManager: discoverPeers, pid:23887, tid:23887, uid:101
These were the devices I tried Samsung M31s, Huawei P20 lite, Huawei P Smart and Xiaomi Mi6.
I already saw this tutorial https://developer.android.com/guide/topics/connectivity/wifip2p but this code looks legit.
Solution 1:[1]
i think you could use another phone to be Service(GO), use the following code:
//first to check your wifi group is already have a GO
wifiP2pManager.requestGroupInfo(appChannel, new WifiP2pManager.GroupInfoListener() {
@Override
public void onGroupInfoAvailable(WifiP2pGroup wifiP2pGroup) {
if (wifiP2pGroup != null){
//if already have a GO, try to remove it, and make this phone tobe the new GO
wifiP2pManager.removeGroup(appChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
//remove success, try tobe the new GO
wifiP2pManager.createGroup(appChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
//you are the new GO, can let another phone to start discover you(this phone)
}
@Override
public void onFailure(int i) {
//fail tobe the new GO, log the reason
}
});
}
@Override
public void onFailure(int reason) {
//remove fail, log the reason
}
});
}else {
//the group doesn't have GO, go ahead tobe the new GO
wifiP2pManager.createGroup(appChannel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
//you are the new GO, can let another phone to start discover you(this phone)
}
@Override
public void onFailure(int i) {
//fail tobe the new GO, log the reason
}
});
}
}
});
after tobe the GO, you can let another phone(it will be GC) to start discover you(this phone)
hope my answer will help you~
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | dawenwhen |