I've made a simple test application for reading RabbitMQ queues using java amqp lib (implementation 'com.rabbitmq:amqp-client:5.7.1'
).
But im having trouble when connecting to my rabbit server due to Android permissions (socket)
Here is the error message:
W/System.err: java.net.SocketException: socket failed: EPERM (Operation not permitted)
I've tried, successless, to add android.permission.INTERNET
to the manifest. Here is what it looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidwebsocket">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
What am I missing?
Edit
As requested, here is the full error stacktrace: https://pastebin.com/WAh2B4rP
And the code that triggers this error:
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("myuser");
factory.setPassword("mypass");
factory.setVirtualHost("/");
factory.setHost("myhost.io");
factory.setPort(5672);
connection = factory.newConnection(); //Error triggers here
channel = connection.createChannel();
I was missing
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
It should mentioned that connections MUST run in Background Threads, or otherwhise android will block it.
Also:
Uninstall app from emulator as suggested in java.net.SocketException: socket failed: EPERM (Operation not permitted)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With