3
votes

I am developing an application that periodically sends data through an UDP socket. For the moment, my code worked well until I tried to test the application with Android.

The code that I am using is:

m_outputSocket.writeDatagram (data, QHostAddress (robotAddress()), m_outputPort);

I have set the following permissions accordingly on the AndroidManifest.xml file:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>

Update, I also added the INTERNET permission, but it still does not work

<uses-permission android:name="android.permission.INTERNET"/>

Running on Android, my application fails to send and receive data through UDP sockets. As a side note, the writeDatargram function returns -1 (indicating an error according to Qt's documentation).

Notes:

  • I am using Qt 5.6 with the Android SDK v19
  • The code works on Windows and Linux, but not on Android
  • The writeDatagram function returns -1
  • I have set permissions accordingly on the AndroidManifest.xml file
  • I have tried this solution, but the application crashes while initializing.

Is there anything that can be done to get UDP working on Android with Qt?

1
Have you tried different android devices? And have you tried emulator as well as physical devices? I got my UDP to work without adding any permissions or making any changes at all. I just recompiled what worked in ubuntu to android target and it worked. Also what version of Qt, and what non-standard build options are you using?Lennart Rolland
Also are you using multicast or just P2P?Lennart Rolland
@LennartRolland I haven't tried the simulator yet, hopefully it will give some results. I am using standard build options, except that I set qmake to use C++11, tested Qt versions where 5.5 and 5.6.Alex Spataru
I am using a P2P connection.Alex Spataru

1 Answers

0
votes

You should add INTERNET permission too. This permission allows applications to open network sockets.

<uses-permission android:name="android.permission.INTERNET"/>