如何以编程设定的时间到设备时间、设备

2023-09-12 04:08:48 作者:‖▍°葬爱

我已创建了一个应用程序,取代目前的放映时间和服务器时间。我已经尝试了很多,但我没有找到一个解决方案。我怎样才能将它设置为我的设备?

I have created one application that replace the current showing time with server time. I have tried a lot, but I didn't find a solution. How can I set it to my device?

我知道如何让我的Andr​​oid设备上的服务器时间。是否有可能在实时,特别是在Android?

I know how to get the server time on my Android device. Is it possible in real time, specially on Android?

在服务器时会自动设置为我的设备上我的按钮单击事件。

推荐答案

如果你有正确的权限(见下文),您可以用 AlarmManager 。例如,设置为2013/08/15 12:34:56的时候,你可以这样做:

If you have the correct permission (see below), you can do this with the AlarmManager. For example, to set the time to 2013/08/15 12:34:56, you could do:

Calendar c = Calendar.getInstance();
c.set(2013, 8, 15, 12, 34, 56);
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.setTime(c.getTimeInMillis());

您需要的权限 SET_TIME 做到这一点。不幸的是,这是一个signatureOrSystem许可。

You need the permission SET_TIME to do this. Unfortunately, this is a signatureOrSystem permission.

在AndroidManifest.xml:

    <!-- Allows applications to set the system time -->
    <permission android:name="android.permission.SET_TIME"
        android:protectionLevel="signature|system"
        android:label="@string/permlab_setTime"
        android:description="@string/permdesc_setTime" />

西门子plc设定设备运行时间

这可以用此权限的唯一应用程序是:

The only apps that can use this permission are:

签订了系统映像 已安装到 /系统/ 文件夹 Signed with the system image Installed to the /system/ folder

除非你建立自定义光盘,你的运气与第一位。

Unless you build custom ROMs, you're out of luck with the first.

对于第二个,这取决于你在做什么。

For the second, it depends on what you are doing.

如果你正在构建广泛分发的应用程序(谷歌播放等),你可能不应该。它仅适用于root用户的​​选项,你就只能手动安装它。任何市场不会将其安装到正确的位置。

If you're building an app for wide distribution (Google Play, etc.), you probably shouldn't. It's only an option for root users, and you'll only be able to install it manually. Any marketplace would not install it to the correct location.

如果您正在构建自己的应用程序(或者只是作为一个学习锻炼),去了。你需要一个根深蒂固的电话,不过,这样做第一。然后,您可以直接将应用程序安装到 /系统/应用/ 与亚行或文件管理器。见文章这样获取更多详细信息。

If you're building an app for yourself (or just as a learning exercise), go for it. You'll need a rooted phone, though, so do that first. You can then install the application straight to /system/app/ with ADB or a file manager. See articles like this for more detail.

最后要注意的是: SET_TIME 许可和 AlarmManager#的setTime()分别加入了Android 2.2( API 8 )。如果你想做到这一点在previous版本,我不知道它会在所有的工作。

One final note: The SET_TIME permission and AlarmManager#setTime() were added in Android 2.2 (API 8). If you're trying to do this on a previous version, I'm not sure it will work at all.

 
精彩推荐
图片推荐