2

我想测试处理电话,所以我做了一个小应用程序,它应该在呼入/呼出电话上写一个日志。这是广播接收器:第一个:

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

public class IncomingCallReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    Log.d("DEBUGING", "INCOMING CALL DETECTED !!");

     }
}

第二个:

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

public class OutgoingCallReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    Log.d("DEBUGING", "OUTGOING CALL DETECTED !!");

     }
}

最后是清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.callrec"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <receiver android:name=".IncomingCallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
    </receiver>
    <receiver android:name=".OutgoingCallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>
</application>

问题是我的接收者从来没有被叫过....我不知道为什么,有人可以帮忙吗?

4

1 回答 1

2

显然,从 3.1+ 开始,您的接收器只有在用户至少对您的活动进行一次操作后才会开始工作,所以我没有活动的应用程序将无法工作

于 2012-07-25T17:49:36.787 回答