Fixing WSS Link Not Opening in Android When Received from MQTT Message
When working with MQTT-based communication between an IoT device and a mobile app, I encountered an issue where a WebSocket Secure (WSS) link received in the app was not recognized as a clickable link on Android.
Instead of treating the URL as a link, Android was interpreting it as plain text, which prevented the app from properly handling the connection.
This article explains the problem and the solution that fixed it.
The Problem
In our application architecture:
- The device communicates with the server using MQTT
- The server sends a message to the mobile app
- The message contains a WSS URL for establishing a secure WebSocket connection
Example message received from MQTT:
wss://example-server.com/device/connect?id=12345However, when this message arrived in the Android app:
- The system treated the URL as normal text
- The WSS connection failed
- The app could not properly initiate the WebSocket connection
This happens because Android does not automatically recognize wss:// schemes as supported deep links unless they are configured in the app.
Root Cause
Android only recognizes certain URL schemes by default:
http://https://
But ws:// and wss:// are not automatically handled unless the app explicitly declares support for them.
Get Mayank Pratap Singh’s stories in your inbox
Join Medium for free to get updates from this writer.
So even though the message contained a valid WSS URL, Android did not treat it as a link or supported URI.
The Solution
To fix this issue, we needed to configure the Android app to accept ws and wss schemes.
This can be done by adding an intent filter inside the AndroidManifest.xml.
Step 1: Open AndroidManifest
Navigate to:
android/app/src/main/AndroidManifest.xmlStep 2: Add Intent Filter
Inside your main activity, add the following:
<intent-filter>
<data android:scheme="ws" />
<data android:scheme="wss" />
</intent-filter>Example:
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<data android:scheme="ws"/>
<data android:scheme="wss"/>
</intent-filter>
</activity>Result
After adding this configuration:
- Android correctly recognized the WSS URL
- The app was able to process the WebSocket connection
- MQTT messages containing
wss://links started working correctly
Key Takeaway
When working with WebSocket connections (ws:// or wss://) in Android, make sure your app explicitly declares support for these schemes.
Otherwise, Android may treat them as plain text instead of valid URIs.
Final Thoughts
This issue can easily appear in IoT architectures where MQTT messages trigger WebSocket connections. If your Android app receives a wss:// link but fails to process it correctly, checking the AndroidManifest intent filters can save hours of debugging.





