Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission for sockets - android manifest

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();
like image 797
CarlosCarucce Avatar asked Mar 04 '23 20:03

CarlosCarucce


1 Answers

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)

like image 77
CarlosCarucce Avatar answered Mar 10 '23 09:03

CarlosCarucce