0

I have a device with android that connects to wi-fi with a certificate. The certificate has a specific validity time. If the battery is removed or completely discharged, the time is reset. This results in the inability to connect to wi-fi and download the correct time. For security reasons, the settings are locked in the device and I would like to create an application that will set the time to a fixed time in the code. Then the phone will connect to the network and download the correct one. Do you have any other suggestions on how to solve it?

1 Answers1

0

If I remember correctly you need a root device, plus the "SET_TIME" permission. that's a system permission so you can't do that in a Play Store app.

Then you can use the AlarmManager to set the time you want.

Calendar c = Calendar.getInstance();
c.set(2021, 11, 19, 11, 46, 00);
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.setTime(c.getTimeInMillis());

EDIT: How to set time to device programmatically

Geobits's answers this better than me in a really similar way.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Gerard E
  • 27
  • 9