gpt4 book ai didi

java - 套接字权限 - android list

转载 作者:行者123 更新时间:2023-11-30 10:02:49 26 4
gpt4 key购买 nike

我已经制作了一个简单的测试应用程序,用于使用 java amqp lib(implementation 'com.rabbitmq:amqp-client:5.7.1')读取 RabbitMQ 队列。

但是由于 Android 权限(套接字),我在连接到我的兔子服务器时遇到了问题

这是错误信息:

W/System.err: java.net.SocketException: socket failed: EPERM (Operation not permitted)

我已尝试将 android.permission.INTERNET 添加到 list 中,但未成功。这是它的样子:

<?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>

我错过了什么?

编辑

根据要求,这里是完整的错误堆栈跟踪:https://pastebin.com/WAh2B4rP

以及触发此错误的代码:

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();

最佳答案

我不见了

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

应该提到连接必须在后台线程中运行,否则 android 将阻止它。

还有:

按照中的建议从模拟器中卸载应用程序 java.net.SocketException: socket failed: EPERM (Operation not permitted)

关于java - 套接字权限 - android list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56582336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com