【问题标题】:Change the system date and time android programmatically [duplicate]以编程方式更改系统日期和时间android [重复]
【发布时间】:2016-04-20 23:05:16
【问题描述】:

我正在尝试为我的应用程序设置日历:

Calendar c = Calendar.getInstance();
c.set(2010, 1, 1, 12, 00, 00);
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.setTime(c.getTimeInMillis());

权限:

android.permission.SET_TIME_ZONE

遇到异常: 用户 10215 和当前进程都没有 android.permission.SET_TIME。

【问题讨论】:

  • 从错误信息中可以清楚的看出你的应用没有设置时间的权限。
  • 你解决了吗?无论如何,我认为您需要超级用户访问权限。

标签: android calendar


【解决方案1】:

从您的错误消息中可以清楚地看出,您的应用无权更改系统时间。

在manifest.xml中使用此权限

 <permission android:name="android.permission.SET_TIME"
    android:protectionLevel="signature|system"/>

见documentation here

【讨论】:

  • 不供第三方应用使用。
【解决方案2】:

将此添加到您的清单中

  <permission android:name="android.permission.SET_TIME"
               android:protectionLevel="signature|system"
    />

【讨论】:

  • 不供第三方应用使用。
猜你喜欢
  • 2010-10-13
  • 1970-01-01
  • 2018-03-03
  • 2018-08-29
  • 2015-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多