-3

I have a button it should work according to time from 09.00 Am to 04.00 pm and rest of time it should not work.

I am developing an app. I am new in android. I have three buttons namely register, events, gallery.

When I click register button it should work according to time mentioned above. if the user click register on that time it should pass on to the next activity and rest of times the button click action should not work.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

-1

check for class AlarmManager

on app start create AlarmManage class service with time gap current to desable/enable time in milisecond.

public class MyReceiver extends BroadcastReceiver {
    private static final int PERIOD = 1200000;//20*60*1000; 20 minutes


    @Override
    public void onReceive(Context ctxt, Intent i) {
        scheduleAlarms(ctxt);
    }

    public static void scheduleAlarms(Context ctxt) {
        AlarmManager mgr =
                (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
        Intent i = new Intent(ctxt, AuthenticateService.class);
        PendingIntent pi = PendingIntent.getService(ctxt, 0, i, 0);
        mgr.setRepeating(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + PERIOD, PERIOD, pi);
    }