Home > Software design >  Is there a function in android which enable user to login only at specified time intervals?
Is there a function in android which enable user to login only at specified time intervals?

Time:12-27

I am working on attendance app as a part of my college project. I want to include a function such that the user can login only at specific time period. lets say from 9:30 a.m to 9:40 a.m. After that the login should be disabled for another 40 minutes and enable for the next 10 minutes. This process should repeat for 8 times a day, i.e; from 9:30 a.m in the morning till 4:10 p.m in the evening. The function should reset for every new day.

I used firebase as the backend for my project.

I have tried to setting the timer during the login screen but that didn't work out. I was expecting that the login buttton should be valid for only 10 minutes and be disabled for another 40 minutes . This cycle should repeat for 8 times a day, starting from the specified time in android, lets say at 9:30 a.m. I am new to android development and i don't know how to proceed from here on. I need guidance on how to implement this function.

CodePudding user response:

First off, Android Studio is an IDE- a fancy text editor. It has no functionality. You don't even need it to write an Android program. So I'll assume you wanted to ask if the Android OS had something built in for that.

The answer is no- the Android OS doesn't do app logins, so it has no ability to control when they could happen. You'd need to write that yourself. In a real app, you'd have your server doing that and either not allowing logins outside that time, or more likely just not allowing editing of data outside that time (but still allowing viewing of data). It really shouldn't be done clientside at all, because someone can break your app just by changing the time on their phone. Doing it on the server means you have an authoritative and trusted source of time.

If you're forced into firebase (which I really wouldn't suggest for an app where anything where the user needs to be prevented from doing things), then you need to add a check for the time before writing any data to it. It wouldn't be a good choice of infrastructure for an actual production app, but that can be good enough for a school project.My suggestion is to write a class DatabaseManager that encapsulates your firebase information and provides an API to read and set the data. That layer could include the check when writing to the db. Then in the rest of your app, use that object rather than directly accessing firebase. That's a best practice anyway- always hide the implementation of what your db is from the rest of your app, you never know when it might change.

  • Related