套接字权限-Android清单 [英] Permission for sockets - android manifest

查看:128
本文介绍了套接字权限-Android清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个简单的测试应用程序,用于使用java amqp lib(实现'com.rabbitmq:amqp-client:5.7.1')读取RabbitMQ队列。 / p>

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



这是错误消息:



W / System.err:java.net.SocketException:套接字失败:EPERM(不允许操作)



我尝试不成功地将 android.permission.INTERNET 添加到清单中。看起来像这样:

 <?xml version = 1.0 encoding = utf-8?> 
<清单xmlns:android = http://schemas.android.com/apk/res/android
package = com.example.androidwebsocket>

<使用权限android:name = android.permission.INTERNET />

<应用程序
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工厂= new ConnectionFactory(); 
factory.setUsername( myuser);
factory.setPassword( mypass);
factory.setVirtualHost( /);
factory.setHost( myhost.io);
factory.setPort(5672);

connection = factory.newConnection(); //错误在这里触发
channel = connection.createChannel();


解决方案

我丢失了

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

应该提及的是,连接必须在后台线程中运行,否则其他的android将会阻止它。



也:



按照
java.net.SocketException:套接字失败:EPERM(不允许操作)


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 connectiong 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)

这篇关于套接字权限-Android清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆