[英]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'
).我制作了一个简单的测试应用程序,用于使用 java amqp lib (
implementation 'com.rabbitmq:amqp-client:5.7.1'
) 读取 RabbitMQ 队列。
But im having trouble when connecting to my rabbit server due to Android permissions (socket)但是由于Android权限(套接字),我在连接到我的兔子服务器时遇到了麻烦
Here is the error message:这是错误消息:
W/System.err: java.net.SocketException: socket failed: EPERM (Operation not permitted) W/System.err:java.net.SocketException:套接字失败:EPERM(不允许操作)
I've tried, successless, to add android.permission.INTERNET
to the manifest.我尝试将
android.permission.INTERNET
添加到清单中,但没有成功。 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根据要求,这是完整的错误堆栈跟踪: 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.应该提到连接必须在后台线程中运行,否则android会阻止它。
Also:还:
Uninstall app from emulator as suggested in java.net.SocketException: socket failed: EPERM (Operation not permitted)按照java.net.SocketException 中的建议从模拟器中卸载应用程序:套接字失败:EPERM(不允许操作)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.