可以从我的Andr​​oid应用程序设置系统日期时间? [英] Is possible to set System DateTime from my Android App?

查看:319
本文介绍了可以从我的Andr​​oid应用程序设置系统日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 SystemClock.setCurrentTimeMillis 来设置系统时钟,但遇到了以下错误:

I want to set system clock by SystemClock.setCurrentTimeMillis, but met following error:

"Unable to open alarm driver: Permission denied"

下面是 setCurrentMillis API从Android开发者网站上的说明:

Below is the Description of setCurrentMillis API from Android Developers Site:

public static boolean setCurrentTimeMillis (long millis) 

自:API级别1设置当前挂钟时间,以毫秒为单位。需要调用进程具有相应的权限。

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.

因此​​,应用程序需要获得权限设置时间。 在 AndroidManisfest.xml 我插入 android.permission.SET_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.

我曾尝试在互联网上找到各种解决方案,似乎是不可能的,甚至在升级Froyo(And​​roid 2.2的),其中 android.permission.SET_TIME 据介绍,正常的应用程序无法获得此权限,因为的/ dev /报警文件具有 664允许。因此,解决办法是改变许可 666 ,但需要root权限的设备和过于侵入性是一个解决方案。

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.

感谢您提前为您的意愿

日食

推荐答案

日食,

我做了相当多的关于这个检查你的,发现一个开放的车票与谷歌来解决这个问题。唯一的一点是标签一直开着,因为11月8日,2009年基本上只有系统可以更改时间甚至与权限。据低于开发商的链接评论做了一些研究,并指出,创建权限SET_TIME的时候,它没有给出操作系统相应的保护级别(signatureorSystem VS危险)。因此,它不会做什么是应该做的。

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.

<一个href="http://$c$c.google.com/p/android/issues/detail?id=4581">http://$c$c.google.com/p/android/issues/detail?id=4581

下面是不同的保护级别的权限可以有一种解释。目前根据开发商举上面的SET_TIME有signatureorSystem时,它应该有危险的。

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".

<一个href="http://developer.android.com/guide/topics/manifest/permission-element.html#plevel">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.

最后要注意的是,如果你想要去的自定义光盘也有一个开放式票的CyanogenMod的能力添加到他们的ROM为好。

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.

<一个href="http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=CyanogenMod+SET_TIME">http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=CyanogenMod+SET_TIME

希望这有助于一些, 乔治

Hope this helps some, George

这篇关于可以从我的Andr​​oid应用程序设置系统日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆