I followed https://developer.android.com/develop/connectivity/wifi/wifi-direct to get my application to create a wifi direct group. And the createGroup() call fails with an rc of 2:
this.manager.createGroup(this.channel, new WifiP2pManager.ActionListener() {
@Override
public void onSuccess() {
notifyActionToListeners(WIFI_DIRECT_MANAGER_FORMED_CONNECTION_SUCCESSFUL,
"Group created for " + deviceName);
}
@Override
public void onFailure(int reasonCode) {
notifyActionToListeners(WIFI_DIRECT_MANAGER_FORMED_CONNECTION_FAILED,
"Could not create group for " + deviceName + " rc = " + reasonCode);
logger.log(WARNING, "Failed to create a group with reasonCode: " + reasonCode);
}
});
I call this after WifiP2pManager.initialize() has returned successfully.
I’m testing on both android 13 (Galaxy s20) and android 14 (Galaxy S24).
These are the permissions in the manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.CHANGE_WIFI_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.NEARBY_WIFI_DEVICES"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I have prompted for the required permissions. (initialize() was not returning successfully before I did.)
Digging through the Android sources, the rc == 2 might be a BUSY return code. I noticed and API 36 they introduced GROUP_CREATION_FAILURE_REASON_USER_REJECTED.
Has anyone successfully managed a createGroup()?