我想测试处理电话,所以我做了一个小应用程序,它应该写一个传入/拨出电话的日志。这是广播接收器: 第一:
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>
问题是我的接收者从未被召唤过......我不知道为什么,有人可以帮忙吗?
答案 0 :(得分:2)
显然,从3.1+开始,只有在用户对您的活动进行了至少一次操作后,您的接收器才会开始工作,因此我的没有活动的应用将无法正常工作