Tiago
Tiago

Reputation: 732

How Change Date and Time inside my App (not via settings), best way to do it?

I'm building an app that will be bundled with an equipment. I want to block all access to Android settings, there is not physical button to go back, only touchscreen. So this won't help: startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));

I want to change time and date of the device through the Application. I researched a lot and every solution I've found to change time and date programatically in Android seems to be over complicated (putting the app inside system/app or something).

As I've come to know, having superuser access and declaring SET_TIME on AndroidManifest only doesn't help.

The application must display hh:mm dd/mm/yyyy

In my App settings, the user may set the date as being 13/01/2014 (dd-mm-yyyy), but let's say today is 10/01/2013. In my app I would do something like this today+offset (3 days). The same goes for the clock.

I was thinking in creating a thread that keeps track of the current time to update the text field with the current time (+offset defined by the user) every minute and another to update the date (the machine may work for a very long time), where I format it using the offset the user configured in the App. I don't like this solution, however I'm not sure if Android has another more efficient way to do this kind of task.

So the question: Is there a better way to do it other than using threads?

I was thinking in using a thread with postAtTime(), I guess it's more efficient than being inside a loop and checking if the time/date has changed from time to time.

Upvotes: 1

Views: 24545

Answers (1)

Tiago
Tiago

Reputation: 732

I found out the answer I needed here: Setting system time of ROOTED phone

My Android device is rooted and using CrazyCoder solution worked. Although it will not work on Android emulator, but with rooted device.

Upvotes: 1

Related Questions