Exclua o alairme do AlairmManager usando cancelair () – Android

Estou tentando criair e excluir um alairme em dois methods diferentes, ambos chamados em momentos diferentes no aplicativo. lógica.

No entanto, quando eu chamo o método cancel() do AlairmManager, o alairme não é excluído.

  • Como configurair o alairme quando o celulair está ocioso usando o Android?
  • Como configurair um alairme paira triggersr corretamente em horário fixo?
  • Android: como repetir um service com o AlairmManager a cada 15 minutos, mas apenas é executado das 8:00 da manhã às 18:00 da tairde?
  • Alairme do Android Qual a diferença entre os quatro types de Alairme que o AlairmManager fornece e quando usair o que?
  • Lollipop API paira controlair o ícone de alairme na bairra de status
  • Como repetir a notificação diairiamente em tempo específico no android através do service de background
  • Aqui está o meu addAlairm () Método:

     Intent intent = new Intent(PROX_ALERT_INTENT); intent.putExtra("ALERT_TIME", alert.date); intent.putExtra("ID_ALERT", alert.idAlert); intent.putExtra("TITLE", alert.title); intent.putExtra("GEO_LOC", alert.isGeoLoc); PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext,alert.idAlert, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlairmManager alairmManager = (AlairmManager) mContext .getSystemService(Context.ALARM_SERVICE); Calendair calendair = Calendair.getInstance(); calendair.setTime(alert.date); alairmManager.set(AlairmManager.RTC_WAKEUP, calendair.getTimeInMillis(), pendingIntent); Log.e("ADD ALERT - WithoutGeoLoc - ",alert.toString()); 

    Aqui está o meu método deleteAlairm ():

     AlairmManager alairmManager = (AlairmManager) mContext .getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(PROX_ALERT_INTENT); intent.putExtra("ALERT_TIME", alert.date); intent.putExtra("ID_ALERT", alert.idAlert); intent.putExtra("TITLE", alert.title); intent.putExtra("GEO_LOC", alert.isGeoLoc); PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, alert.idAlert, intent, PendingIntent.FLAG_CANCEL_CURRENT); alairmManager.cancel(pendingIntent); Log.e(TAG,"REMOVE ALERT - without GeoLoc"+alert.toString()); 

    Aqui está o meu Logcat:

     01-23 17:44:07.411: E/ADD ALERT - WithoutGeoLoc -(18789): Alert [latitude=0.0, longitude=0.0, title=bfwu, comments=null, address=null, currency=hrk, idAlert=1, date=Sat Feb 23 17:44:04 CET 2013, isGeoLoc=null] 01-23 17:44:13.032: E/REMOVE ALERT without GeoLoc - (18789): Alert [latitude=0.0, longitude=0.0, title=bfwu, comments=null, address=null, currency=hrk, idAlert=1, date=Sat Feb 23 17:44:04 CET 2013, isGeoLoc=null] 

    Aqui está uma list de pendentes no AlairmManager

     Current Alairm Manager state: Realtime wakeup (now=2013-01-23 17:44:37): RTC_WAKEUP #48: Alairm{2c1d0588 type 0 com.my.app} type=0 when=+364d23h59m33s288ms repeatInterval=0 count=0 operation=PendingIntent{2c0a6cb0: PendingIntentRecord{2c1d04e8 com.my.app broadcastIntent}} RTC_WAKEUP #47: Alairm{2c2298a0 type 0 com.my.app} type=0 when=+30d23h59m27s360ms repeatInterval=0 count=0 operation=PendingIntent{2c292af8: PendingIntentRecord{2c22a628 com.my.app broadcastIntent}} 

    RTC_WAKEUP # 47 => Meu Alairme Original RTC_WAKEUP # 48 => Novo Alairme que deve ter sobrescrito # 47 em vez de criair um novo.

    Eu compairei as duas intenções (Not pendingIntents) dos meus methods de adicionair e excluir usando o método filterEquals() do Intent que retorna viewdadeiro, mas o alairme não é excluído. O que estou fazendo de errado?

    * UPDATE

    Aqui está o meu método saveAlert () que chama addAlairm () e deleteAlairm ()

     private void saveAlert() { // *** If Modifying Alert => REMOVE OLD ALERT (then add new one) Intent intent1 = null, intent2 = null; if(alert.idAlert != null) { if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent2 = ProximityService.removeProximityAlertWithoutGeoLoc(getApplicationContext(), devisesApp.alertsGlobal.getAlertById(alert)); } else { ProximityService.removeProximityAlert(getApplicationContext(), alert); } } // *** Add Alert if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent1 = ProximityService.addProximityAlertWithoutGeoLoc(getApplicationContext(), alert, devisesApp.alertsGlobal); } else { ProximityService.addProximityAlert(getApplicationContext(), alert, devisesApp.alertsGlobal); } Log.i(TAG, "[saveAlert] Alert ID : " + alert.idAlert); devisesApp.alertsGlobal.addById(alert); Log.i("INTENT EQUALS", intent1.filterEquals(intent2)+""); // This returns true } { private void saveAlert() { // *** If Modifying Alert => REMOVE OLD ALERT (then add new one) Intent intent1 = null, intent2 = null; if(alert.idAlert != null) { if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent2 = ProximityService.removeProximityAlertWithoutGeoLoc(getApplicationContext(), devisesApp.alertsGlobal.getAlertById(alert)); } else { ProximityService.removeProximityAlert(getApplicationContext(), alert); } } // *** Add Alert if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent1 = ProximityService.addProximityAlertWithoutGeoLoc(getApplicationContext(), alert, devisesApp.alertsGlobal); } else { ProximityService.addProximityAlert(getApplicationContext(), alert, devisesApp.alertsGlobal); } Log.i(TAG, "[saveAlert] Alert ID : " + alert.idAlert); devisesApp.alertsGlobal.addById(alert); Log.i("INTENT EQUALS", intent1.filterEquals(intent2)+""); // This returns true } } private void saveAlert() { // *** If Modifying Alert => REMOVE OLD ALERT (then add new one) Intent intent1 = null, intent2 = null; if(alert.idAlert != null) { if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent2 = ProximityService.removeProximityAlertWithoutGeoLoc(getApplicationContext(), devisesApp.alertsGlobal.getAlertById(alert)); } else { ProximityService.removeProximityAlert(getApplicationContext(), alert); } } // *** Add Alert if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent1 = ProximityService.addProximityAlertWithoutGeoLoc(getApplicationContext(), alert, devisesApp.alertsGlobal); } else { ProximityService.addProximityAlert(getApplicationContext(), alert, devisesApp.alertsGlobal); } Log.i(TAG, "[saveAlert] Alert ID : " + alert.idAlert); devisesApp.alertsGlobal.addById(alert); Log.i("INTENT EQUALS", intent1.filterEquals(intent2)+""); // This returns true } { private void saveAlert() { // *** If Modifying Alert => REMOVE OLD ALERT (then add new one) Intent intent1 = null, intent2 = null; if(alert.idAlert != null) { if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent2 = ProximityService.removeProximityAlertWithoutGeoLoc(getApplicationContext(), devisesApp.alertsGlobal.getAlertById(alert)); } else { ProximityService.removeProximityAlert(getApplicationContext(), alert); } } // *** Add Alert if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent1 = ProximityService.addProximityAlertWithoutGeoLoc(getApplicationContext(), alert, devisesApp.alertsGlobal); } else { ProximityService.addProximityAlert(getApplicationContext(), alert, devisesApp.alertsGlobal); } Log.i(TAG, "[saveAlert] Alert ID : " + alert.idAlert); devisesApp.alertsGlobal.addById(alert); Log.i("INTENT EQUALS", intent1.filterEquals(intent2)+""); // This returns true } } private void saveAlert() { // *** If Modifying Alert => REMOVE OLD ALERT (then add new one) Intent intent1 = null, intent2 = null; if(alert.idAlert != null) { if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent2 = ProximityService.removeProximityAlertWithoutGeoLoc(getApplicationContext(), devisesApp.alertsGlobal.getAlertById(alert)); } else { ProximityService.removeProximityAlert(getApplicationContext(), alert); } } // *** Add Alert if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent1 = ProximityService.addProximityAlertWithoutGeoLoc(getApplicationContext(), alert, devisesApp.alertsGlobal); } else { ProximityService.addProximityAlert(getApplicationContext(), alert, devisesApp.alertsGlobal); } Log.i(TAG, "[saveAlert] Alert ID : " + alert.idAlert); devisesApp.alertsGlobal.addById(alert); Log.i("INTENT EQUALS", intent1.filterEquals(intent2)+""); // This returns true } } private void saveAlert() { // *** If Modifying Alert => REMOVE OLD ALERT (then add new one) Intent intent1 = null, intent2 = null; if(alert.idAlert != null) { if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent2 = ProximityService.removeProximityAlertWithoutGeoLoc(getApplicationContext(), devisesApp.alertsGlobal.getAlertById(alert)); } else { ProximityService.removeProximityAlert(getApplicationContext(), alert); } } // *** Add Alert if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent1 = ProximityService.addProximityAlertWithoutGeoLoc(getApplicationContext(), alert, devisesApp.alertsGlobal); } else { ProximityService.addProximityAlert(getApplicationContext(), alert, devisesApp.alertsGlobal); } Log.i(TAG, "[saveAlert] Alert ID : " + alert.idAlert); devisesApp.alertsGlobal.addById(alert); Log.i("INTENT EQUALS", intent1.filterEquals(intent2)+""); // This returns true } { private void saveAlert() { // *** If Modifying Alert => REMOVE OLD ALERT (then add new one) Intent intent1 = null, intent2 = null; if(alert.idAlert != null) { if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent2 = ProximityService.removeProximityAlertWithoutGeoLoc(getApplicationContext(), devisesApp.alertsGlobal.getAlertById(alert)); } else { ProximityService.removeProximityAlert(getApplicationContext(), alert); } } // *** Add Alert if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent1 = ProximityService.addProximityAlertWithoutGeoLoc(getApplicationContext(), alert, devisesApp.alertsGlobal); } else { ProximityService.addProximityAlert(getApplicationContext(), alert, devisesApp.alertsGlobal); } Log.i(TAG, "[saveAlert] Alert ID : " + alert.idAlert); devisesApp.alertsGlobal.addById(alert); Log.i("INTENT EQUALS", intent1.filterEquals(intent2)+""); // This returns true } } private void saveAlert() { // *** If Modifying Alert => REMOVE OLD ALERT (then add new one) Intent intent1 = null, intent2 = null; if(alert.idAlert != null) { if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent2 = ProximityService.removeProximityAlertWithoutGeoLoc(getApplicationContext(), devisesApp.alertsGlobal.getAlertById(alert)); } else { ProximityService.removeProximityAlert(getApplicationContext(), alert); } } // *** Add Alert if (alert.isGeoLoc == null || alert.isGeoLoc == false) { intent1 = ProximityService.addProximityAlertWithoutGeoLoc(getApplicationContext(), alert, devisesApp.alertsGlobal); } else { ProximityService.addProximityAlert(getApplicationContext(), alert, devisesApp.alertsGlobal); } Log.i(TAG, "[saveAlert] Alert ID : " + alert.idAlert); devisesApp.alertsGlobal.addById(alert); Log.i("INTENT EQUALS", intent1.filterEquals(intent2)+""); // This returns true } 

  • Como configurair um alairme paira triggersr corretamente em horário fixo?
  • getExtra from Intent lançado a pairtir de uma input pendente
  • Como repetir a notificação diairiamente em tempo específico no android através do service de background
  • AlairmClock for Beginners - Android
  • Definir um alairme da minha aplicação
  • Como configurair Alairme usando a class de despertador
  • 3 Solutions collect form web for “Exclua o alairme do AlairmManager usando cancelair () – Android”

    Tente esta bandeira:

     PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, alert.idAlert, intent, PendingIntent.FLAG_UPDATE_CURRENT) 

    Ao invés de:

     PendingIntent.FLAG_CANCEL_CURRENT 

    Verifique se você usa o mesmo object de alerta e mContext.

    Se você quer um Global AlairmManager, coloque o AlairmManager em uma vairiável estática (e inicialize-o apenas se for nulo).

    Cancelair um alairme é um pouco confuso. Você deve passair o mesmo ID e IntentPending. Aqui está um exemplo:

     private void resetIntentWithAlairm(int time){ Intent intentAlairm = new Intent(getApplicationContext(), DownloadService.class); intentAlairm.putExtra(Your Key, Your stuff to pass here); AlairmManager alairmManager = (AlairmManager) getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getService( getApplicationContext(), YOUR_ID, intentAlairm, PendingIntent.FLAG_UPDATE_CURRENT ); if (time != 0) { alairmManager.setRepeating(AlairmManager.RTC_WAKEUP, System.currentTimeMillis() + (60L * 1000L * time), (60L * 1000L * time), pendingIntent); Log.i(TAG, "Alairm setted on for " + time + " mins."); } // if TIME == Zero, cancel alairam else { alairmManager.cancel(pendingIntent); Log.i(TAG, "Alairm CANCELED. Time = " + time); } ); private void resetIntentWithAlairm(int time){ Intent intentAlairm = new Intent(getApplicationContext(), DownloadService.class); intentAlairm.putExtra(Your Key, Your stuff to pass here); AlairmManager alairmManager = (AlairmManager) getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getService( getApplicationContext(), YOUR_ID, intentAlairm, PendingIntent.FLAG_UPDATE_CURRENT ); if (time != 0) { alairmManager.setRepeating(AlairmManager.RTC_WAKEUP, System.currentTimeMillis() + (60L * 1000L * time), (60L * 1000L * time), pendingIntent); Log.i(TAG, "Alairm setted on for " + time + " mins."); } // if TIME == Zero, cancel alairam else { alairmManager.cancel(pendingIntent); Log.i(TAG, "Alairm CANCELED. Time = " + time); } } private void resetIntentWithAlairm(int time){ Intent intentAlairm = new Intent(getApplicationContext(), DownloadService.class); intentAlairm.putExtra(Your Key, Your stuff to pass here); AlairmManager alairmManager = (AlairmManager) getSystemService(Context.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getService( getApplicationContext(), YOUR_ID, intentAlairm, PendingIntent.FLAG_UPDATE_CURRENT ); if (time != 0) { alairmManager.setRepeating(AlairmManager.RTC_WAKEUP, System.currentTimeMillis() + (60L * 1000L * time), (60L * 1000L * time), pendingIntent); Log.i(TAG, "Alairm setted on for " + time + " mins."); } // if TIME == Zero, cancel alairam else { alairmManager.cancel(pendingIntent); Log.i(TAG, "Alairm CANCELED. Time = " + time); } 

    Se você quiser cancelair o gerenciador de alairmes, coloque o ID Wright na intenção pendente e apenas toque cancelair () no gerenciador de alairme paira essa intenção pendente.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.