在Android中以编程方式设置设备时间 [英] set device time programmatically in android
本文介绍了在Android中以编程方式设置设备时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要动态设置设备时间。如果可以,请指导我
I need to set device time dynamically.if it possible please guide me
据我所知
MainActivity.java
Calendar c = Calendar.getInstance();
c.set(2010, 1, 1, 12, 00, 00);
manifest.xml
<permission android:name="android.permission.SET_TIME"
android:protectionLevel="signatureOrSystem"
android:label="@string/app_name" />
预先感谢
推荐答案
//set Time to device
Calendar c = Calendar.getInstance();
c.set(2013, 8, 15, 12, 34, 56);
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.setTime(c.getTimeInMillis());
// and set in Manifest.xml
<!-- Allows applications to set the system time -->
<permission android:name="android.permission.SET_TIME"
android:protectionLevel="signature|system"
/>
并点击此链接获得更多帮助如何在android中设置移动系统的时间和日期?
我认为这可能对您有所帮助
and follow this link for more help How to set mobile system time and date in android? I think it may help u
这篇关于在Android中以编程方式设置设备时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文