I need to sync my android application time with server. How can I achieve the same? or is there any ways to change device time.
Asked
Active
Viewed 1,153 times
2 Answers
0
TimeManager timeManager = TimeManager.getInstance();
// Set clock time to noon
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 12);
long timeStamp = calendar.getTimeInMillis();
timeManager.setTime(timeStamp);
Edit the 0s and 12 as per your choice
NB:
You should add
<uses-permission android:name="com.google.android.things.permission.SET_TIME" />
in your AndroidManifest.xml

AFLAH ALI
- 451
- 5
- 17
0
You cannot do this if you plan to have your app publish in the PlayStore, or update the time to the server time.
You need SignatureOrSystem permission in order to change the time date as per the server.
Check this thread you will get more detail.

Jayesh Khasatiya
- 2,140
- 1
- 14
- 15