我需要创建自定义广播接收器,它会向我显示发生的任何PHONE_STATE事件。
答案 0 :(得分:1)
在您的清单中,您应该定义以下内容:
<receiver
android:enabled="true"
android:label="@string/app_name"
android:name=".PhoneStateReceiver">
<intent-filter>
<action
android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
样本接收器类:
public class PhoneStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
switch(telManager.getCallState()) {
case TelephonyManager.CALL_STATE_IDLE:
//do something
}
}
}