我目前有一个警报管理器和一个广播接收器,可以在每天的特定时间发送通知。目前,每次拨打电话时都会激活通知,我相信这是来自广播接收器的监听电话状态的变化,但我不知道如何阻止它监听电话状态的变化。下面是我的代码:
public class Alarm_Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (return_cow_id.isEmpty()){
}else{
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, Cows_On_Heat.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Cow/s due back on heat today: ")
.setContentText(return_cow_id);
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
if (calve_cow_id.isEmpty()){
}else{
PendingIntent contentIntent1 = PendingIntent.getActivity(context, 0,
new Intent(context, Cows_Calving.class), 0);
NotificationCompat.Builder mBuilder1 =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Cow/s due to calve in 7 days: ")
.setContentText(calve_cow_id);
mBuilder1.setContentIntent(contentIntent1);
mBuilder1.setDefaults(Notification.DEFAULT_SOUND);
mBuilder1.setAutoCancel(true);
NotificationManager mNotificationManager1 =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager1.notify(2, mBuilder1.build());
}
}
}
任何帮助将不胜感激。