【问题标题】:Android Studio - Permission Denial, requires android.permission.RECEIVE_SMS errorAndroid Studio - 权限拒绝,需要 android.permission.RECEIVE_SMS 错误
【发布时间】:2023-03-22 11:33:01
【问题描述】:

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

但是,我意识到我需要 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>

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

【问题讨论】:

    标签: java android android-studio broadcastreceiver sms


    【解决方案1】:

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

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

    【讨论】:

    • 我不知道,但是你会如何将应用程序列入白名单?这不是我打算放在 Play 商店或任何东西上的应用,它只是为了我的手机
    • 您需要在将应用上传到 Playstore 时执行此操作。如果您在清单中包含该权限,则会提示您您的应用具有敏感权限,并且您将获得一个申请理由的地方。同时访问短信的目的是什么?如果您让我知道目的,我可以提出一些替代方案。
    • 是的,它只是我为自己制作的一个项目,它不会出现在 Playstore 上。这是一个始终在后台运行并正在收听我的 SMS 文本的应用程序,如果它收到某个短语,它将向托管我的路由器的 Web 服务器发送一个带有手机纬度和经度的 HTTP POST 请求 - 实际上它只是我自己对 FindMyIphone 式应用程序的看法。不过,为了让它工作,我需要能够阅读 SMS 消息。如果你知道的话,我会对任何替代品感兴趣
    • 在这种情况下,您可以使用 SMSRetriever API 发送短信,它会解决您的问题。更多细节在这里developers.google.com/identity/sms-retriever/overview
    • 很有趣,我会试试看。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    • 1970-01-01
    • 2022-06-22
    • 2019-02-22
    • 2014-01-01
    相关资源
    最近更新 更多