Sending UDP Packets with Phonegap and the In App Browser

To send some instructions to a server process I needed to send UDP packets from an Android device. Normally I would “go native” and java/kotlin but for this one I tried phonegap. This is a reminder of a couple of tweaks needed.

You need this package:-

cordova-plugin-chrome-apps-sockets-udp

ie cordova plugin add cordova-plugin-chrome-apps-sockets-udp

I also wanted to check a web page so used the cordova “in app browser

That worked on older Android but on on newer versions gave the error net::ERR_CLEARTEXT_NOT_PERMITTED .

To fix that needs tweaks in the project config.xml needed the xml android namespace adding as below

<widget id="com.whatever.app" version="1.0.0" 
xmlns=”http://www.w3.org/ns/widgets” 
xmlns:android=”http://schemas.android.com/apk/res/android"
xmlns:gap="http://phonegap.com/ns/1.0">

and in the platform stanza

<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge"   target="/manifest/application">
  <application android:usesCleartextTraffic="true" />
</edit-config>
........rest of the platform entry
</platform>

For more info on this at stackoverflow see here

This entry was posted in android, coding, computing, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply