java.net.SocketException:套接字失败:Android Studio 中的 OPT 申请的 EACCES(权限被拒绝)

java.net.SocketException:socketfailed:EACCES(permission denied) for OTP application in Android Studio

我正在尝试创建一次性密码访问 android 应用程序。我已经使用 wamp 创建了一个本地主机服务器,我正在尝试使用我设计的移动应用程序访问该服务器。不幸的是,我在日志 cat 中收到如下错误:

03-07 10:42:35.097 31217-31217/com.example.user.myapplication V/ActivityThread: updateVisibility : ActivityRecord{1ecab2fb token=android.os.BinderProxy@23c38b5b {com.example.user.myapplication/com.example.user.myapplication.activity.SmsActivity}} show : true
03-07 10:42:36.607 31217-31217/com.example.user.myapplication I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@23c38b5b time:52633449
03-07 10:42:37.397 31217-31217/com.example.user.myapplication D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
03-07 10:42:37.537 31217-32544/com.example.user.myapplication E/SmsActivity: Posting params: {email=thomasbi@gmail.com, name=Thomas, mobile=9002378900}
03-07 10:42:37.537 31217-32544/com.example.user.myapplication I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-07 10:42:37.537 31217-32544/com.example.user.myapplication I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
03-07 10:42:37.547 31217-31217/com.example.user.myapplication E/SmsActivity: Error: java.net.SocketException: socket failed: EACCES (Permission denied)
03-07 10:42:37.617 31217-31217/com.example.user.myapplication D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 

我已经包含了所有权限,这是我的 AndroidManifest.xml 文件

<?xml version="1.0" encoding="utf-8"?>

<application
    android:name=".app.MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/MyMaterialTheme">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />

    <activity
        android:name=".activity.SmsActivity"
        android:label="@string/title_activity_sms">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".activity.MainActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustResize">

    </activity>

    <!-- SMS Receiver -->
    <receiver android:name=".receiver.SmsReceiver">
        <intent-filter android:priority="99999">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>


    <!-- Intent service -->
    <service
        android:name=".service.HttpService"
        android:exported="false" />

</application>

我现在有点困惑,我知道我被一些愚蠢的东西困住了。如果有人能帮助我解决这个问题,我将不胜感激。

如果您的目标是 API 23+ (Marshmallow),则在需要权限时会发出权限请求,否则会导致不良的用户体验。

这个网站有很好的解释和例子: http://www.captechconsulting.com/blogs/runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal