在android中以编程方式设置设备时间

时间:2014-10-13 05:55:30

标签: android datetime time timezone

我需要动态设置设备时间。如果有可能请指导我

我试过

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

提前致谢

1 个答案:

答案 0 :(得分:2)

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

并点击此链接获取更多帮助How to set mobile system time and date in android? 我想这可能对你有所帮助