Using Socket.IO on android Always Returns XHR Poll Error

The problem I faced is strange and typical.

Using Socket.IO on android Always Returns XHR Poll Error.


Not much help available on the net regd. XHR Poll Error but StackOverflow has a quickfix.

Finally the issue was resolved in two steps:

1. CORS (Cross-Origin Resource Sharing).

CORS Configuration: Ensure that your server-side configuration allows cross-origin requests if your client and server are on different domains.

2. In AndroidManifest.xml tweak  android:usesCleartextTraffic

Indicates whether the app intends to use cleartext network traffic, such as cleartext HTTP. The default value for apps that target API level 27 or lower is "true". Apps that target API level 28 or higher default to "false".

When the attribute is set to "false", platform components, for example, HTTP and FTP stacks, DownloadManager, and MediaPlayer, refuse the app's requests to use cleartext traffic.

Since we are running on IT and yet to implement Positive SSL, we have to set it to true.

And here goes the security issues when you set usesCleartextTraffic to True

The application has android:usesCleartextTraffic set to true, which allows it to access resources that do not use encryption, a situation that could be exploited by an attacker to perform MitM attacks and compromise the confidentiality and integrity of the application.

So, use it if absolutely necessary.

The code snippet:

 <application

... android:usesCleartextTraffic="true" ...>

Reference:

Comments

Popular posts from this blog

How to Add Animation to Android App in JAVA

Get Android App Version No and Display in a Text Field

How to Send Crash Report to Email / Mobile Device in Android Java