Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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_Android Manifest_Android Notifications - Fatal编程技术网

Android 安卓:警报通知问题

Android 安卓:警报通知问题,android,notifications,android-manifest,android-notifications,Android,Notifications,Android Manifest,Android Notifications,在我的应用程序中,我设置了许多报警通知。 所有这些都在不同的日期,但时间相同。我通过切换按钮将其设置为开/关 现在的问题是,如果我设置它,那么在那个时候它会通知我从当前日期开始的前一个。它只会一次出现,然后所有报警通知工作正常 假设我已将报警设置为12,14,16日期,然后我在设备中将日期设置为15,然后在切换按钮上,它会在此时通知我14。然后一切都会好起来 那么,它在逻辑上是否正确,或者我的代码中是否存在任何问题 到底该不该发生 请参阅我为报警通知设置的以下代码: public void st

在我的应用程序中,我设置了许多报警通知。 所有这些都在不同的日期,但时间相同。我通过切换按钮将其设置为开/关

现在的问题是,如果我设置它,那么在那个时候它会通知我从当前日期开始的前一个。它只会一次出现,然后所有报警通知工作正常

假设我已将报警设置为12,14,16日期,然后我在设备中将日期设置为15,然后在切换按钮上,它会在此时通知我14。然后一切都会好起来

那么,它在逻辑上是否正确,或者我的代码中是否存在任何问题

到底该不该发生

请参阅我为报警通知设置的以下代码:

public void startTwoMonthAlarmNotification() {

        // ===================== GST ALARM FOR THE TWO MONTHS ==========================
        // for the GST 20 June 2011
        AM_2M_GST_1 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent in1 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
        in1.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 20th June 2011.");
        PI_2M_GST_1 = PendingIntent.getBroadcast(this, 0, in1, PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar_GST_18_June_2011 = Calendar.getInstance();
        calendar_GST_18_June_2011.setTimeInMillis(System.currentTimeMillis());
        calendar_GST_18_June_2011.set(2011, 5, 18, mHour, mMinute, 0);
        AM_2M_GST_1.set(AlarmManager.RTC_WAKEUP,   calendar_GST_18_June_2011.getTimeInMillis(), PI_2M_GST_1);

        // for the GST 19 August 2011
        AM_2M_GST_2 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent in2 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
        in2.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 19th August 2011.");
        PI_2M_GST_2 = PendingIntent.getBroadcast(this, 1, in2, PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar_GST_17_August_2011 = Calendar.getInstance();
        calendar_GST_17_August_2011.setTimeInMillis(System.currentTimeMillis());
        calendar_GST_17_August_2011.set(2011, 7, 17,mHour, mMinute, 0);
        AM_2M_GST_2.set(AlarmManager.RTC_WAKEUP,  calendar_GST_17_August_2011.getTimeInMillis(),PI_2M_GST_2);

        // for the GST 21 October 2011  
        AM_2M_GST_3 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent in3 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
        in3.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 21st October 2011.");
        PI_2M_GST_3 = PendingIntent.getBroadcast(this, 2, in3, PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar_GST_19_October_2011 = Calendar.getInstance();
        calendar_GST_19_October_2011.setTimeInMillis(System.currentTimeMillis());
        calendar_GST_19_October_2011.set(2011, 9, 19,mHour, mMinute, 0);
        AM_2M_GST_3.set(AlarmManager.RTC_WAKEUP,  calendar_GST_19_October_2011.getTimeInMillis(),PI_2M_GST_3);

        // for the GST 17 December 2011 
        AM_2M_GST_4 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent in4 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
        in4.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 19th December 2011.");
        PI_2M_GST_4 = PendingIntent.getBroadcast(this, 3, in4, PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar_GST_17_December_2011 = Calendar.getInstance();
        calendar_GST_17_December_2011.setTimeInMillis(System.currentTimeMillis());
        calendar_GST_17_December_2011.set(2011, 11, 17,mHour, mMinute, 0);
        AM_2M_GST_4.set(AlarmManager.RTC_WAKEUP,  calendar_GST_17_December_2011.getTimeInMillis(),PI_2M_GST_4);
        /////////////////////////////////////
        // for the GST 26 February 2012 
        AM_2M_GST_5 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent in5 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
        in5.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 28th February 2012.");
        PI_2M_GST_5 = PendingIntent.getBroadcast(this, 4, in5, PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar_GST_26_February_2012 = Calendar.getInstance();
        calendar_GST_26_February_2012.setTimeInMillis(System.currentTimeMillis());
        calendar_GST_26_February_2012.set(2012, 1, 26,mHour, mMinute, 0);
        AM_2M_GST_5.set(AlarmManager.RTC_WAKEUP,  calendar_GST_26_February_2012.getTimeInMillis(),PI_2M_GST_5);
        /////////////////////
    // for the GST 27 April 2012    
        AM_2M_GST_6 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent in6 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
        in6.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 29th April 2012.");
        PI_2M_GST_6 = PendingIntent.getBroadcast(this, 5, in6, PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar_GST_27_April_2012 = Calendar.getInstance();
        calendar_GST_27_April_2012.setTimeInMillis(System.currentTimeMillis());
        calendar_GST_27_April_2012.set(2012, 3, 27,mHour, mMinute, 0);
        AM_2M_GST_6.set(AlarmManager.RTC_WAKEUP,  calendar_GST_27_April_2012.getTimeInMillis(),PI_2M_GST_6);

    // for the GST 16 January 2012  
        AM_2M_GST_7 = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent in7 = new Intent(this, AlarmReceiverNotificationForTwoMonth.class);
        in7.putExtra("MyMessage","Your 2 Monthly GST return is DUE on 16th January 2012.");
        PI_2M_GST_7 = PendingIntent.getBroadcast(this, 6, in7, PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar_GST_16_January_2012 = Calendar.getInstance();
        calendar_GST_16_January_2012.setTimeInMillis(System.currentTimeMillis());
        calendar_GST_16_January_2012.set(2012, 0, 14,mHour, mMinute, 0);
        AM_2M_GST_7.set(AlarmManager.RTC_WAKEUP,  calendar_GST_16_January_2012.getTimeInMillis(),PI_2M_GST_7);
        }
以下代码用于取消toogleButton off上的所有通知报警:

        AM_2M_GST_1.cancel(PI_2M_GST_1);
    AM_2M_GST_2.cancel(PI_2M_GST_2);
    AM_2M_GST_3.cancel(PI_2M_GST_3);
    AM_2M_GST_4.cancel(PI_2M_GST_4);
    AM_2M_GST_5.cancel(PI_2M_GST_5);
    AM_2M_GST_6.cancel(PI_2M_GST_6);
    AM_2M_PROVISIONAL_1.cancel(PI_2M_PROVISIONAL_1);
    AM_2M_PROVISIONAL_2.cancel(PI_2M_PROVISIONAL_2);
    AM_2M_PROVISIONAL_3.cancel(PI_2M_PROVISIONAL_3);
    AM_2M_TERMINAL_1.cancel(PI_2M_TERMINAL_1);

首先,必须取消旧的AlarmManager和挂起的意图。在这里,您没有取消您的待定意图。只需取消使用thic代码即可-

alaramManagerObj.cancel(pendingIntent);
pendingIntent.cancel();
这将清除您不想要的通知,并且仅适用于提供的警报。如果要检查指定日期的报警,则该日期是否已过。看看这个-

Calendar c = Calendar.getInstance(); 
c.set(2011, 1, 20); 
long mills = c.getTimeInMillis(); 
long currentTime = System.currentTimeMillis(); 
int x = (mills<=currentTime)?0:1; 
Calendar c=Calendar.getInstance();
c、 一套(2011年1月20日);
长磨机=c.getTimeInMillis();
长currentTime=System.currentTimeMillis();

int x=(mills首先您必须取消旧的AlarmManager和挂起的意图。这里您没有取消挂起的意图。只需使用thic代码取消即可-

alaramManagerObj.cancel(pendingIntent);
pendingIntent.cancel();
这将清除您不需要的通知,并且仅适用于提供的警报。如果您希望检查指定日期的警报,则该日期是否已过。只需使用此选项进行检查-

Calendar c = Calendar.getInstance(); 
c.set(2011, 1, 20); 
long mills = c.getTimeInMillis(); 
long currentTime = System.currentTimeMillis(); 
int x = (mills<=currentTime)?0:1; 
Calendar c=Calendar.getInstance();
c、 一套(2011年1月20日);
长磨机=c.getTimeInMillis();
长currentTime=System.currentTimeMillis();

整数x=(Mills可能是索引问题。你应该发布一些代码n的东西。@dokkaebi:请查看更新的问题。我用它来设置警报。有什么问题吗?我的逻辑设置了吗?@dokkaebi:你知道如何解决它或者为什么会这样吗?可能是索引问题。你应该发布一些代码n的东西。@dokkaebi:请看更新的问题。我用它来设置警报。有什么问题吗?我的逻辑设置了吗?@dokkaebi:你知道怎么解决它或者为什么会这样吗?