Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission Denial: requires android.permission.READ_PHONE_STATE

Tags:

c#

.net

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:

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

And my broadcast receiver:

[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");
        }
    }
}

What I am missing ?

like image 776
Entretoize Avatar asked Aug 23 '18 13:08

Entretoize


People also ask

What does Android permission Query_all_packages mean?

Google Play restricts the use of high-risk or sensitive permissions, including the QUERY_ALL_PACKAGES permission, which gives visibility into the inventory of installed apps on a given device.

What is READ_PHONE_STATE permission?

permission. READ_PHONE_STATE - You must ask the end user to grant this permission.) Allows read only access to the phone's state, and is used to determine the status of any ongoing calls. You need this permission so you can verify that your end user receives a phone call from TeleSign. android.

How do I enable permissions in Android 11?

Starting in Android 11, whenever your app requests a permission related to location, microphone, or camera, the user-facing permissions dialog contains an option called Only this time. If the user selects this option in the dialog, your app is granted a temporary one-time permission.


1 Answers

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

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.

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).

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.

like image 81
Kevin Coppock Avatar answered Sep 26 '22 14:09

Kevin Coppock