Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 即使使用两个使用广播接收器的类,我也无法在不同的时间创建两个通知_Android_Notifications_Alarmmanager_Android Notifications_Android Broadcastreceiver - Fatal编程技术网

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>