可以从我的 Android 应用程序设置系统日期时间吗?
我想通过 SystemClock.setCurrentTimeMillis
设置系统时钟,但遇到以下错误:
"Unable to open alarm driver: Permission denied"
下面是来自 Android 开发者站点的 setCurrentMillis
API 的说明:
public static boolean setCurrentTimeMillis (long millis)
自:API Level 1 设置当前时钟墙上时间,以毫秒为单位。要求调用进程有适当的权限。
退货 如果时钟已成功设置为指定时间。
因此,应用程序需要获得设置时间的权限。 在 AndroidManisfest.xml 中,我插入了 android.permission.SET_TIME
但出现了相同的消息错误。
我尝试了在互联网上找到的各种解决方案,似乎即使在引入 android.permission.SET_TIME
的 FroYo (Android 2.2) 上也无法在没有 root 的情况下设置系统时间,普通应用程序无法获取此权限是因为 /dev/alarm 文件具有 664 权限
。因此,解决方案是更改 666
中的权限,但需要 root 设备,并且侵入性太大,无法作为解决方案。
我想为我的公司创建一个应用程序来同步不同系统之间的数据,并且同步时钟至关重要。
预先感谢您的愿意
Eclipses
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Eclipses,
我对此做了很多检查,并找到了 Google 的开放票来解决该问题。唯一的问题是该标签自 2009 年 11 月 8 日以来一直处于开放状态。即使有权限,基本上也只有系统可以更改时间。根据下面链接上的评论,开发人员做了一些研究,并指出,当创建权限 SET_TIME 时,操作系统中没有为其提供适当的保护级别(签名或系统与危险)。结果它没有做它应该做的事情。
http://code.google.com/p/android/issues/detail ?id=4581
以下是权限可以具有的各种保护级别的说明。目前根据上面引用的开发人员的说法,SET_TIME 具有“signatureorSystem”,而它应该具有“危险”。
http://developer.android.com/guide/topics/manifest /permission-element.html#plevel
简而言之,目前无法在不 root 手机的情况下以编程方式更改时间。
最后要注意的是,如果您想使用自定义 rom,Cyanogenmod 也可以为他们的 rom 添加此功能。
http://www.google.com/search ?sourceid=chrome&ie=UTF-8&q=CyanogenMod+SET_TIME
希望这对一些人有帮助,
乔治
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
根据 这篇文章,SET_TIME 是正确的权限,但它仅适用于已 root 的手机。
According to this post, SET_TIME is the correct permission but it will only work on a rooted phone.
我们已经做到了。只要你能获得 SET_TIME 权限就没什么大不了的。请参阅我的对类似问题的回答。
关于其他答案指出如果不root手机就不可能,那么这仅指获得许可。有关此信息,请参阅此处和此处。
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.