Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intercepting outgoing call - what am I missing?

Tags:

android

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.

like image 424
Scot Avatar asked Jun 06 '11 15:06

Scot


1 Answers

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

like image 99
Scot Avatar answered Oct 18 '22 04:10

Scot