简体   繁体   English

用于在 Android 上读取用户区域设置的 API

[英]API to read user's locale settings on Android

I am trying to see if there is any API I can use to read the user's settings like date/time etc on Android device.我想看看是否有任何 API 可以用来在 Android 设备上读取用户的设置,如日期/时间等。 If the user selects 24 hour format or changes any other setting, I should be able to know about it.如果用户选择 24 小时制或更改任何其他设置,我应该能够了解它。

Any info on this will be helpful.任何有关这方面的信息都会有所帮助。

Thanks in advance.提前致谢。

There is no all encompassing API to gather user settings.没有包罗万象的 API 来收集用户设置。 You will need to query a few different APIs to get what you need.您将需要查询一些不同的 API 以获得所需的内容。

One is Device一是Device

Device.getLocale()
Device.getScreenSize()

is the common way to get the current locale setting.是获取当前区域设置的常用方法。

If you want to get an update when the user changes it you could try a broadcast receiver like in this answer:如果您想在用户更改时获得更新,您可以尝试使用广播接收器,如以下答案:

Android - Listening to a locale change without static variables Android - 在没有静态变量的情况下侦听区域设置更改

You can access the user date preferences via DateFormat.您可以通过 DateFormat 访问用户日期首选项。

DateFormat.is24HourFormat(context)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用用户的区域设置时用秒格式化日期和时间 - Format date and time with seconds while using user's locale settings 如何保存用户的区域设置(在应用程序中)? - How do I save user's locale settings (in app)? 要求权限以在Android中读取用户的电子邮件Graph API - Ask permission to read user's email Graph API in android Joda和Android:如何设置日期格式以在用户的​​语言环境中显示? - Joda & Android: How to format a date for display in the user's locale? java android DateFormat忽略修改的语言环境设置 - java android DateFormat ignores modified locale settings 从API &lt;17开始从Settings.Global读取Android? - Android Read from Settings.Global from API < 17? Android:从另一个应用程式读取应用程式的设定 - Android: Read app's settings from the another app Android上的用户区域设置有多准确? - How accurate is the user locale on Android? 如果我的GLSurfaceView应用程序永远不需要读取Android设备的语言环境,是否可以安全地忽略语言环境配置更改? - If my GLSurfaceView app never needs to read the Android device's locale, can I safely ignore locale config changes? api:android:textDirection =“ locale” - android:textDirection=“locale” for api 15
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM