Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-34111

Android doesn't receive UDP Multicast Packets by default - Workaround

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Invalid
    • Affects Version/s: 5.1.1
    • Fix Version/s: None
    • Component/s: QPA
    • Labels:
      None
    • Platform/s:
      Android

      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.

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            esabraha Eskil Abrahamsen Blomfeldt
            Reporter:
            miketrahearn Mike Trahearn
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes