拦截拨出电话 - 我错过了什么?

Sco*_*cot 5 android

我正在尝试编写一个简单的应用程序来捕获ACTION_NEW_OUTGOING_CALL意图并编写一些调试信息.

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.android.apis"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <receiver android:name="DialerReceiver" android:exported="false" android:enabled="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"></uses-permission>
</manifest> 
Run Code Online (Sandbox Code Playgroud)

这是DialerReceiver的代码:

package com.example.android.apis;

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

public class DialerReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        // TODO Auto-generated method stub
        debugOut("arg0: " + arg0.toString());
        debugOut("arg1: " + arg1.toString());
        debugOut("isOrderedBroadcast = " + isOrderedBroadcast());
    }

    private static void debugOut(String str) {
        Log.i("DialerReceiver", str);
    }
}
Run Code Online (Sandbox Code Playgroud)

由于我不明白的原因,当我安装它并发起拨出电话时,我收到以下错误:

WARN/ActivityManager(59): Permission Denial:
broadcasting Intent { act=android.intent.action.NEW_OUTGOING_CALL (has extras) } 
from com.android.phone (pid=123, uid=1001) requires null
due to receiver com.example.android.apis/com.example.android.apis.DialerReceiver
Run Code Online (Sandbox Code Playgroud)

是什么赋予了?似乎PROCESS_OUTGOING_CALLS应该足够了.

FWIW,如果我更改为没有权限的通知(例如TIMEZONE_CHANGED),这就像魅力一样.

提前致谢.

Sco*_*cot 6

回答我自己的问题.

在查看我的清单之后,它似乎android:exported="false"是不正确的,因为Android本身需要调用DialerReceiver.

当我改变它时android:export="true",一切都很好.

FWIW,我是针对模拟器(API版本8和版本10设备)执行此操作的.