为什么我无法在锁屏中获取 Settings.System.DATE_FORMAT?

发布于 2024-11-17 03:19:45 字数 1849 浏览 2 评论 0原文

这是android中锁屏的一些代码。 日期格式是:

mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);

我设置:

mDateFormatString =Settings.System.getString(getContext().getContentResolver(), Settings.System.DATE_FORMAT) ;

为什么我无法在LockScreen中获取Settings.System.DATE_FORMAT?

private void resetStatusInfo(KeyguardUpdateMonitor updateMonitor) {
    mShowingBatteryInfo = updateMonitor.shouldShowBatteryInfo();
    mPluggedIn = updateMonitor.isDevicePluggedIn();
    mBatteryLevel = updateMonitor.getBatteryLevel();

    /* for dual sim, by jing.wang */
    mStatus[SimCardID.ID_ZERO.toInt()] = getCurrentStatus(updateMonitor.getSimState());
    if (isDualMode) {
        mStatus[SimCardID.ID_ONE.toInt()] = getCurrentStatus(updateMonitor.getSimState (SimCardID.ID_ONE));
        updateLayout(mStatus[SimCardID.ID_ZERO.toInt()], SimCardID.ID_ZERO, mStatus[SimCardID.ID_ONE.toInt()]);
        updateLayout(mStatus[SimCardID.ID_ONE.toInt()], SimCardID.ID_ONE, mStatus[SimCardID.ID_ZERO.toInt()]);
    } else {
        updateLayout(mStatus[SimCardID.ID_ZERO.toInt()]);
    }

    refreshBatteryStringAndIcon();
    refreshAlarmDisplay();

    mTimeFormat = DateFormat.getTimeFormat(getContext());
    mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);

    refreshTimeAndDateDisplay();
    updateStatusLines();
}

编辑:我想修改锁屏代码。我想显示我在设置中设置的日期格式。但现在我设置日期格式“dd-MM-yyyy”,它无法在锁定屏幕中显示。日期以mDateFormatString的格式显示。

mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year); 

这是refreshTimeAndDateDisplay的代码。

private void refreshTimeAndDateDisplay() {
    mDate.setText(DateFormat.format(mDateFormatString, new Date()));
} 

This is some Code of the LockScreen in android.
The dateformat is:

mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);

And I set:

mDateFormatString =Settings.System.getString(getContext().getContentResolver(), Settings.System.DATE_FORMAT) ;

Why I can't get Settings.System.DATE_FORMAT in the LockScreen?

private void resetStatusInfo(KeyguardUpdateMonitor updateMonitor) {
    mShowingBatteryInfo = updateMonitor.shouldShowBatteryInfo();
    mPluggedIn = updateMonitor.isDevicePluggedIn();
    mBatteryLevel = updateMonitor.getBatteryLevel();

    /* for dual sim, by jing.wang */
    mStatus[SimCardID.ID_ZERO.toInt()] = getCurrentStatus(updateMonitor.getSimState());
    if (isDualMode) {
        mStatus[SimCardID.ID_ONE.toInt()] = getCurrentStatus(updateMonitor.getSimState (SimCardID.ID_ONE));
        updateLayout(mStatus[SimCardID.ID_ZERO.toInt()], SimCardID.ID_ZERO, mStatus[SimCardID.ID_ONE.toInt()]);
        updateLayout(mStatus[SimCardID.ID_ONE.toInt()], SimCardID.ID_ONE, mStatus[SimCardID.ID_ZERO.toInt()]);
    } else {
        updateLayout(mStatus[SimCardID.ID_ZERO.toInt()]);
    }

    refreshBatteryStringAndIcon();
    refreshAlarmDisplay();

    mTimeFormat = DateFormat.getTimeFormat(getContext());
    mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);

    refreshTimeAndDateDisplay();
    updateStatusLines();
}

Edit: I want to modify the lock screen code. And I want to display the dateformat which I set in setting. But now I set the dateformat "dd-MM-yyyy", it can't display in the lock screen. The date display by the format of mDateFormatString.

mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year); 

This is the code of refreshTimeAndDateDisplay.

private void refreshTimeAndDateDisplay() {
    mDate.setText(DateFormat.format(mDateFormatString, new Date()));
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请别遗忘我 2024-11-24 03:19:45

您可能应该看看这个: 如何使用设置中默认设置的日期格式? (getDateFormatOrder 为您提供用户的格式设置)

You should probably look at this : How to use the date format that has been setup as default in Settings? (getDateFormatOrder gives you the user's format setting)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文