Android 即使使用两个使用广播接收器的类,我也无法在不同的时间创建两个通知
这是我试图调用这两种方法来创建通知的主要类Android 即使使用两个使用广播接收器的类,我也无法在不同的时间创建两个通知,android,notifications,alarmmanager,android-notifications,android-broadcastreceiver,Android,Notifications,Alarmmanager,Android Notifications,Android Broadcastreceiver,这是我试图调用这两种方法来创建通知的主要类 夜间显示通知(小时,分钟), shownotificationAtMorning(小时,分钟) 另一类接受者 class AlarmReceiver extends BroadcastReceiver { int MID = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE); @Override public void onReceive(Context co
夜间显示通知(小时,分钟)
,
shownotificationAtMorning(小时,分钟)
另一类接受者
class AlarmReceiver extends BroadcastReceiver {
int MID = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
@Override
public void onReceive(Context context, Intent intent) {
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, ToTask.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotifyBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(
context).setSmallIcon(meg)
.setContentTitle("Tommorow Plan")
.setContentText("Events To be Performed").setSound(alarmSound)
.setAutoCancel(true).setWhen(when)
.setContentIntent(pendingIntent)
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
notificationManager.notify(MID, mNotifyBuilder.build());
MID++;
}
}
您是否相应地编辑了清单
<receiver android:name=".MyBroadcastReceiver"></receiver>
class AlarmReceiver extends BroadcastReceiver {
int MID = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
@Override
public void onReceive(Context context, Intent intent) {
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, ToTask.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotifyBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(
context).setSmallIcon(meg)
.setContentTitle("Tommorow Plan")
.setContentText("Events To be Performed").setSound(alarmSound)
.setAutoCancel(true).setWhen(when)
.setContentIntent(pendingIntent)
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
notificationManager.notify(MID, mNotifyBuilder.build());
MID++;
}
}
<receiver android:name=".MyBroadcastReceiver"></receiver>