【问题标题】:Intercepting outgoing call - what am I missing?拦截拨出电话 - 我错过了什么?
【发布时间】:2013-06-03 14:59:05
【问题描述】:

我正在尝试编写一个简单的应用程序来捕获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> 

这是 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);
    }
}

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

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

什么给了?看来 PROCESS_OUTGOING_CALLS 应该足够了。

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

提前致谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    回答我自己的问题。

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

    当我将其更改为 android:export="true" 时,一切正常。

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

    【讨论】:

      【解决方案2】:

      我还在拦截拨出电话以采取行动。我也只有添加的权限 PROCESS_OUTGOING_FILES,但我注意到在 DialerReceiver 声明中我设置了优先级:

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

      这个设置对我来说很好。如果需要,我可以从 DialerReceiver 类中发布一些代码。你是用模拟器还是手机测试这个?我只针对实际手机进行了测试。我没有使用模拟器。 希望这会有所帮助。

      【讨论】:

      • 非常感谢您的回复。优先级不是必需的,但你的回复确实让我重新审视了我的清单。问题是 android:exported="false"。删除它使一切正常。
      猜你喜欢
      • 2010-11-30
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多