问题描述
我正在尝试在我的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:
第二,当您的应用程序在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!