Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change android phone's System date on button click from android application

Tags:

date

android

I trying some stuffs with android as i am learning android development, now i have a scenario here.

  • I want to change the android phone's system date through my application( first i would like to know is this doable? )

Layout is as below

layout

Now what i want is when the user clicks the button the date should increase by say 20 days how can i do this.

i am unable to start...please help

like image 612
karan Avatar asked Jun 05 '13 19:06

karan


People also ask

How does Android sync Date and time?

Update Date & Time on Your Android DeviceTap Settings to open the Settings menu. Tap Date & Time. Tap Automatic. If this option is turned off, check that the correct Date, Time and Time Zone are selected.

Why is my automatic Date and time wrong Android?

Turn Automatic Date Settings On and Off Go to Settings > General management or System > Date and time and turn the Automatic date and time button off and then back on. These settings may vary slightly depending on your device. In most cases, this action should readjust your clock to the accurate time.


1 Answers

As I already said that's impossible. You need the SET_TIME permission and that permission is granted by system only to applications that are in the Android system image. If You are able to gain that privilege you can easily change with the AlarmManager. SystemClock.setCurrentTimeMillis write the /dev/allarm file

adb shell ls -l /dev/alarm
crw-rw-r-- system   radio     10,  46 2013-06-12 10:46 alarm
  • c stays for Character special file (stored in /dev).
  • system is the owner of the file
  • radio is the group

system and radio have read and write permissions (rw-, tree bits, int value 6), the others have only the read permission (r, int value 4). So the file permission is 664. If you can get root user (running su), you can change the permission of this file and wrote in it a new value. A bug report has been filled in order to ask google to allow apps to modify programmatically the mobile date but it has been declied. Here the reference

like image 62
Blackbelt Avatar answered Nov 15 '22 08:11

Blackbelt