android - Using AlarmManager to activate and deactivate silence mode -


in program, getting 2 dates user. first date activating silence mode , second date deactivating it. handling issue, have tried use 2 different alarmmanager , 2 different broadcastreceiver couldn't achieve it. can activate silence mode @ first date couldn't deactivate it. part of code:

public class addevent extends appcompatactivity {     private static pendingintent silenceactivatorpendingintent;     private static pendingintent silencedeactivatorpendingintent;     private static alarmmanager manager1;     private static alarmmanager manager2;      @override     protected void oncreate(bundle savedinstancestate) {         intent silenceactivatorintent = new intent(this, silencemodeactivator.class);         intent silencedeactivatorintent = new intent(this, silencemodedeactivator.class);         silenceactivatorpendingintent = pendingintent.getbroadcast(this, 0, silenceactivatorintent, 0);         silencedeactivatorpendingintent = pendingintent.getbroadcast(this, 0, silencedeactivatorintent, 0);         manager2 = (alarmmanager)getsystemservice(context.alarm_service);         manager1 = (alarmmanager)getsystemservice(context.alarm_service);    }     public void addevent(view view) {        gregoriancalendar targetstartdate = new gregoriancalendar(startyear, startmonth, startday, starthour, startminute, 0);        gregoriancalendar targetenddate = new gregoriancalendar(endyear, endmonth, endday, endhour, endminute, 0);        manager1.set(alarmmanager.rtc_wakeup, targetstartdate.gettimeinmillis(), silenceactivatorpendingintent);        manager2.set(alarmmanager.rtc_wakeup, targetenddate.gettimeinmillis(), silencedeactivatorpendingintent);    }     public static void stopalarm1() {     manager1.cancel(silenceactivatorpendingintent);    }     public static void stopalarm2() {     manager2.cancel(silencedeactivatorpendingintent);   } } 

addevent button clicker method.

silence mode activator:

public class silencemodeactivator extends broadcastreceiver {  @override public void onreceive(final context context, intent intent) {     activatesilentmode(context);     addevent.stopalarm1(); }  public void activatesilentmode(context context) {      notificationmanager mnotificationmanager = (notificationmanager)context.getsystemservice(context.notification_service);      // check if notification policy access has been granted app.     if (!mnotificationmanager.isnotificationpolicyaccessgranted()) {         intent intent = new intent(android.provider.settings.action_notification_policy_access_settings);         context.startactivity(intent);     }      mnotificationmanager.setinterruptionfilter(notificationmanager.interruption_filter_none); } } 

silence mode deactivator:

public class silencemodedeactivator extends broadcastreceiver {  @override public void onreceive(context context, intent intent) {     deactivatesilentmode(context);     addevent.stopalarm2(); }  public void deactivatesilentmode(context context) {      notificationmanager mnotificationmanager = (notificationmanager)context.getsystemservice(context.notification_service);      // check if notification policy access has been granted app.     if (!mnotificationmanager.isnotificationpolicyaccessgranted()) {         intent intent = new intent(android.provider.settings.action_notification_policy_access_settings);         context.startactivity(intent);     }      mnotificationmanager.setinterruptionfilter(notificationmanager.interruption_filter_all); } } 

do have idea how can fix this? in advance.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -