Details
-
Suggestion
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.1.1
-
None
Description
By default, receiving UDP Multicast packets from Android is disabled.
Even if you join a multicast group after binding to the correct address and port, no data arrives when you know it is being sent.
The reason is explained below and has nothing to do with the Qt implementation on Android:
http://developer.android.com/reference/android/net/wifi/WifiManager.MulticastLock.html
To make it work, please perform the following steps:
1) Add the following permissions to the Android Manifest:
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
2) Add the following import statements to
<your app>\android\src\org\qtproject\qt5\android\bindings\QtActivity.java
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.MulticastLock;
3) In the same file, add the following into the onCreate() function just after the call to super.onCreate(savedInstanceState)
/* Turn off multicast filter */
WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if (wifi != null){
WifiManager.MulticastLock lock = wifi.createMulticastLock("mylock");
lock.acquire();
}
Rebuild your android application and package it up and your Qt application should now receive UDP Multicast packets.