开发者

Intercepting outgoing call - what am I missing?

I'm trying to write a simple app to capture the ACTION_NEW_OUTGOING_CALL intent and write some debugging information.

Here is my manifest:

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

And here is the code for 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);
    }
}

For reasons that I do not understand, when I install this and initiate an outgoing call, I get the following error:

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

What gives? It seems like PROCESS_OUTGOING_CALLS should be sufficient.

FWIW, if I change to a notification without permissions (TIMEZONE_CHANGED, for example), this works like a charm.

Thanks in advance.


Answering my own question.

After reviewing my manifest, it seemed like android:exported="false" was incorrect, since Android itself would need to invoke DialerReceiver.

When I changed this to android:export="true", everything worked just fine.

FWIW, I did this against the emulator (API version 8 and version 10 devices).


I am also intercepting outgoing calls to take an action. I also only have the added permission, PROCESS_OUTGOING_FILES, but I did notice that in my DialerReceiver declaration I am setting a priority:

<receiver 
   android:name="DialerReceiver"
   android:enabled="true">
   <intent-filter android:priority="2147483647">
      <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
   </intent-filter>
</receiver>

This setup works fine for me. I can post some code from the DialerReceiver class if you need it. Are you testing this against an emulator or a phone? I have only tested against an actual phone. I am not using an emulator. Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜