Android Studio - 权限被拒绝,需要 android.permission.RECEIVE_SMS 错误

Android Studio - Permission Denial, requires android.permission.RECEIVE_SMS error

所以,我一直在抓取每一个文档页面和 Whosebug 页面来寻找答案,但实际上我一无所获。今天我一直在制作一个应用程序,它需要读取我收到的所有短信并搜索特定的短语。

但是,我意识到我需要 RECEIVE_SMS 权限,我确实这样做了 - 权限被拒绝。

鉴于 SDK 超过 22 - 权限被拒绝,因此我为应用程序添加了向用户请求权限的功能。

我已经插入了我在这些论坛中发现的所有小东西,但似乎没有任何效果,无论我做什么,它仍然说权限被拒绝,而且我无法阅读 SMS 消息。

如果有人能提供帮助,我们将不胜感激,因为目前看来,该应用程序似乎已经失败了。

这是错误的样子:

2019-10-30 14:50:53.097 1403-1413/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x19000010 (has extras) } to ProcessRecord{cb5e9afd0 1159:com.samsung.android.email.provider/u0a68} (pid=1159, uid=10068) requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)

这是 MainActivity 文件:

package app.genyie.tnat;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private static final int PERMISSIONS_REQUEST_RECEIVE_SMS = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        requestPermissions(Manifest.permission.RECEIVE_SMS, PERMISSIONS_REQUEST_RECEIVE_SMS);
    }

    private void requestPermissions(String permission, int requestCode) {
        // Here, thisActivity is the current activity
        if (ContextCompat.checkSelfPermission(this, permission)
                != PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

                // Show an explanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try again to request the permission.
                Toast.makeText(this, "Granting permission is necessary!", Toast.LENGTH_LONG).show();

            } else {

                // No explanation needed, we can request the permission.

                ActivityCompat.requestPermissions(this,
                        new String[]{permission},
                        requestCode);

                // requestCode is an
                // app-defined int constant. The callback method gets the
                // result of the request.
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case PERMISSIONS_REQUEST_RECEIVE_SMS: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                    // permission was granted, yay! Do the
                    // contacts-related task you need to do.



                } else {

                    // permission denied, boo! Disable the
                    // functionality that depends on this permission.


                }
                return;
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }
}

这是清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="app.genyie.tnat">

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION" />
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-sdk android:minSdkVersion="26"/>

    <application
        android:name=".App"
        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>

        <service android:name=".BGServ"/>

        <receiver
            android:name=".SmsListener">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>

如果您需要任何其他文件,请告诉我,谢谢您的宝贵时间!

出于安全考虑,阅读短信权限正式取消。 如果您仍然需要它,则需要申请白名单。

https://proandroiddev.com/no-more-sms-call-log-permissions-now-what-9b8226de7827