简体   繁体   English

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

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

So, I have been scraping every single doc page and StackOverflow page to find an answer for this and I have literally found nothing.因此,我一直在抓取每个文档页面和 StackOverflow 页面来寻找答案,但实际上我一无所获。 Today I have been making an app that needs to read all SMS's I receive and search for a specific phrase.今天我一直在制作一个需要阅读我收到的所有短信并搜索特定短语的应用程序。

However, I realized I needed the RECEIVE_SMS permission, which I did - permission denied.但是,我意识到我需要 RECEIVE_SMS 权限,我确实做到了 - 权限被拒绝。

So I added the capability for the app to ask for permissions from the user, given the SDK is over 22 - permission denied.因此,鉴于 SDK 超过 22,我添加了应用程序向用户请求权限的功能 - 权限被拒绝。

I have plugged in every little thing I have found throughout these forums and nothing seems to be working, no matter what I do it still says permission denied and I can't read the SMS messages.我已经插入了我在这些论坛中找到的所有小东西,但似乎没有任何效果,无论我做什么,它仍然显示权限被拒绝并且我无法阅读 SMS 消息。

If anyone could help it would be much appreciated because at the moment it's beginning to look like the app is a lost cause.如果有人可以提供帮助,我们将不胜感激,因为目前它开始看起来像该应用程序是一个失败的事业。

This is what the error looks like:这是错误的样子:

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)

Here is the MainActivity file:这是 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
        }
    }
}

And here is the Manifest:这是清单:

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

If you need any other files let me know, thank you for your time!如果您需要任何其他文件,请告诉我,谢谢您的时间!

Read SMS permission is officially taken off due to security concerns.出于安全考虑,阅读短信权限已正式取消。 If you still need it, you would need to apply for whitelisting.如果您仍然需要它,则需要申请白名单。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM