拒绝权限:需要android.permission.READ_PHONE_STATE [英] Permission Denial: requires android.permission.READ_PHONE_STATE

查看:3733
本文介绍了拒绝权限:需要android.permission.READ_PHONE_STATE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的android应用中检测电话,但收到电话时会收到以下消息:

I'm trying to detect phone calls in my android app but I receive the following message when receiving a call:

08-23 15:16:04.685  Vodafone VFD 600    Warning 850 BroadcastQueue  Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to com....LogCalls requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)
08-23 15:16:04.549  Vodafone VFD 600    Warning 850 BroadcastQueue  Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to com....LogCalls requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)

My AndroidManifest.xml:

My AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com...." android:installLocation="preferExternal">
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="27" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <application android:label="myapp" android:icon="@drawable/logo">
    </application>
</manifest>

我的广播接收器:

[BroadcastReceiver]
[IntentFilter(new[] {TelephonyManager.ActionPhoneStateChanged,Intent.ActionNewOutgoingCall })]
public class LogCalls : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
        if (intent.Action == TelephonyManager.ActionPhoneStateChanged)
        {
            Console.WriteLine("state changed");
        }
    }
}

我想念的是什么?

推荐答案

首先,不允许第三方应用获取 READ_PRIVILEGED_PHONE_STATE 允许。请参见特权许可白名单

Firstly, third-party apps are not permitted to acquire the READ_PRIVILEGED_PHONE_STATE permission. See Privileged Permission Whitelisting:


特权应用程序是位于系统映像/ system / priv-app目录中的系统应用程序。从历史上看,设备实施者几乎无法控制哪些特权可以授予特权应用。从Android 8.0开始,实施者可以在/ etc / permissions目录中的系统配置XML文件中将特权应用明确列入白名单。未在这些XML文件中未明确列出的应用程序未被授予特权。

Privileged applications are system applications located in the /system/priv-app directory on the system image. Historically, device implementers had little control over which signature|privileged permissions could be granted to privileged apps. Starting in Android 8.0, implementors can explicitly whitelist privileged apps in the system configuration XML files in the /etc/permissions directory. Apps not explicitly listed in these XML files are not granted privileged permissions.

第二,当您的应用程序在API 23及更高版本上运行时,您首先需要要求用户在运行时授予您 READ_PHONE_STATE 权限,因为它被视为危险权限(请参阅权限概述)。

Secondly, when your app is running on API 23 and above, you'll need to first ask the user to grant you the READ_PHONE_STATE permission at runtime, as it is considered a "dangerous" permission (see Permissions Overview).

您需要按照请求应用程序权限,以在运行时向用户请求权限,只有授予该权限后,您的 BroadcastReceiver 才能收到意图。

You'll need to follow the instructions at Request App Permissions to request the permission from the user at runtime, and only once that permission is granted can your BroadcastReceiver receive the intents.

这篇关于拒绝权限:需要android.permission.READ_PHONE_STATE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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