I want to set system clock by SystemClock.setCurrentTimeMillis
, but met following error:
"Unable to open alarm driver: Permission denied"
Below is the Description of setCurrentMillis
API from Android Developers Site:
public static boolean setCurrentTimeMillis (long millis)
Since: API Level 1 Sets the current wall time, in milliseconds. Requires the calling process to have appropriate permissions.
Returns
if the clock was successfully set to the specified time.
So, Application Needs to obtain the Permission to set the time.
In AndroidManisfest.xml I inserted android.permission.SET_TIME
but I have the same message error.
I have tried various solutions found in the internet and it seems that it's not possible to set system time without root even on FroYo (Android 2.2) where android.permission.SET_TIME
was introduced, normal application can't get this permission because /dev/alarm file has 664 permission
. So the solution is to change permission in 666
but require rooted device and is too invasive to be a solution.
I want to create an App for my Company to synchronize data between different systems and is essential to have synchronized clocks.
Thank you in advance for your willingness
Eclipses
Eclipses,
I did quite a bit of checking for you on this and found an open ticket with Google to fix the problem. Only thing is the tag has been open since Nov 8, 2009. Basically only the system can change the time even with the Permission. According to comments on the link below a developer did some research and noted that when the permission SET_TIME was created, it wasn't given the appropriate protection level in the OS (signatureorSystem v.s dangerous). As a result it doesn't do what it is supposed to do.
http://code.google.com/p/android/issues/detail?id=4581
Here's an explanation of the various protection levels that permissions can have. Currently according to the developer cite above SET_TIME has "signatureorSystem" when it should have "dangerous".
http://developer.android.com/guide/topics/manifest/permission-element.html#plevel
In short there is currently no way to change the time programatically without rooting the phone.
One final note is that if you want to go with Custom roms there is also an open ticket for Cyanogenmod to add the ability to their rom as well.
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=CyanogenMod+SET_TIME
Hope this helps some,
George
According to this post, SET_TIME is the correct permission but it will only work on a rooted phone.
we've done it. Not a big deal as long as you can get the SET_TIME pemission. See my answer to a similar question.
Regarding other answers stating that it's not possible without rooting the phone then this refers only to gaining the permission. For this see here and here.