广播接收器的权限拒绝 [英] Permission Denial With Broadcast Receiver

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

问题描述

我正在尝试创建一个应用程序,当我拨打电话时输入日志消息。

I am trying to create an app which enters a log message when I make an outgoing call.

然而,当我运行代码时,我得到了拒绝权限,尽管我已经输入了权限。

However, when I run the code, I get a permission denial, despite the fact that I have entered in the permissions.

拒绝日志:

09-04 02:35:50.535 1294-1666 /?W / BroadcastQueue:权限拒绝:接收Intent {act = android .intent.action.NEW_OUTGOING_CALL flg = 0x10000010(有额外的)}到samples.varma.packagecom.testreceive2 / .CallReceiver需要android.permission.PROCESS_OUTGOING_CALLS由于发送者android(uid 1000)

"09-04 02:35:50.535 1294-1666/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.NEW_OUTGOING_CALL flg=0x10000010 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.PROCESS_OUTGOING_CALLS due to sender android (uid 1000)"

清单代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="samples.varma.packagecom.testreceive2" >
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="23" />


    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >


        <activity
            android:name=".MainActivity"
            android:enabled="true"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <receiver
            android:name=".CallReceiver">


            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE"/>
                <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
            </intent-filter>
        </receiver>
    </application>


</manifest>

以下是我的收件人的代码:

And here is the code for my receiver:

package samples.varma.packagecom.testreceive2;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CallReceiver extends BroadcastReceiver {
    public CallReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        if (state == null) {
            String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Log.i("TAG", "Outgoing Number: " + number);
        } else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Log.i("TAG", "Incoming Number: " + number);
        }
    }
        }

我对此非常陌生所以很有可能存在多个错误,或者我完全偏离了基础。无论我多么感激任何指导。有谁知道为什么我会拒绝这个?

I am very new to this so there is a good chance that there are several errors or I am completely off base. Regardless I would greatly appreciate any guidance. Would anyone know why I am getting this denial?

谢谢

编辑:

这是即使我已经添加了手机状态权限,也会拒绝这些权限。

It is also giving me these permission denials even though I have added the phone state permission.

特权电话状态权限是系统权限,因此我无法添加。

The privileged phone-state permission is a system permission so I cannot add.

09-04 04:36:03.249    1294-1440/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)
09-04 04:36:03.271    1294-1308/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)

 1294-1308/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)


推荐答案

我按照此链接开始工作密切关注拦截拨出电话 - 我缺少什么?(感谢ajit)

I got it to work by following this link closely Intercepting outgoing call - what am I missing? (thanks ajit)

我最终取消 PHONE_STATE 权限,添加 android:enabled =true android:exported =true到清单中的接收器,重新定位 NEW_OUTGOING_CALL 对以下应用程序的许可(不确定是否有必要),删除预期的sdk版本并基本上从链接复制接收器。

I ended up taking off the PHONE_STATE permission, adding android:enabled="true" and android:exported="true" to my receiver in the manifest, relocating the NEW_OUTGOING_CALL permission to below application(not sure if this is necessary), taking away the intended sdk versions and basically copying the receiver from the link.

从接收者标签到清单标签的更新清单代码是:

Updated manifest code from receiver tag to manifest tag is:

    <receiver
            android:name=".testreceive3"
            android:enabled="true"
            android:exported="true" >
            <intent-filter>

                <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>-->
            </intent-filter>
        </receiver>
    </application>

     <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />>-->

 </manifest>

这篇关于广播接收器的权限拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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