E
E
Eugene2018-05-18 08:33:14
Android
Eugene, 2018-05-18 08:33:14

How to protect application from substitution of local time?

The situation is the following. There is an application in which it is possible to work without connecting to the Internet, at this time all operations in the application are recorded according to the time of the phone, and after the appearance of the network, everything is sent to the server en masse.
I guessed to attach a broadcast receiver to ACTION_TIMEZONE_CHANGED and ACTION_TIME_CHANGED, but it already works after the fact - i.e. after the user has changed the time and it is not clear how to find out how much time has left.
Submit an implementation idea.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexDeww, 2018-05-18
@klim76

Why not use server time.
При появлении связи, синхронизируешь время.

object ServerTime {

    private var serverOffset: Long = System.currentTimeMillis() - SystemClock.elapsedRealtime()

    fun getTime(): Long = SystemClock.elapsedRealtime() + serverOffset

    fun syncTime(serverTime: Long) {
        serverOffset = serverTime - SystemClock.elapsedRealtime()
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question