怎么用DataAbility读取系统设置项
本篇内容介绍了“怎么用Data Ability读取系统设置项”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
成都创新互联服务项目包括平谷网站建设、平谷网站制作、平谷网页制作以及平谷网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,平谷网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到平谷省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
SystemSettingUtil工具类
public class SystemSettingUtil { private static final int LOG_DOMAIN = 218107648; private static final String TAG = "SystemSettingUtil"; private static final HiLogLabel LOG_LABEL = new HiLogLabel(0, LOG_DOMAIN, TAG); private static final String LOG_FORMAT = "%{public}s"; private static final String GET_GLOBAL = "GET_global"; private static final String GET_SECURE = "GET_secure"; private static final String GET_SYSTEM = "GET_system"; private static final String SETTING_VALUE = "value"; private static final String SYSTEM_SETTING = "dataability:///settings"; public static String getGlobal(String key) { return getSettingValueAsString(key, GET_GLOBAL); } public static String getSecure(String key) { return getSettingValueAsString(key, GET_SECURE); } public static String getSystem(String key) { return getSettingValueAsString(key, GET_SYSTEM); } public static String getSettingValueAsString(String key, String method) { if (TextTool.isNullOrEmpty(key)) { HiLog.warn(LOG_LABEL, LOG_FORMAT, "getSettingValueAsString -> key is null or empty"); return ""; } else if (TextTool.isNullOrEmpty(method)) { HiLog.warn(LOG_LABEL, LOG_FORMAT, "getSettingValueAsString -> method is null or empty"); return ""; } else { try { return DataAbilityHelper.creator(ContextUtil.getHapGlobalContext()).call(Uri.parse(SYSTEM_SETTING), method, key, null).getString(SETTING_VALUE, ""); } catch (IllegalArgumentException | IllegalStateException | DataAbilityRemoteException e) { HiLog.error(LOG_LABEL, LOG_FORMAT, "getSettingValueAsString -> Exception"); return ""; } } } }
ContextUtil工具类
public class ContextUtil { private static Context sHapGlobalContext; public static Context getHapGlobalContext() { return sHapGlobalContext; } public static void setHapGlobalContext(Context context) { if (context != null) { sHapGlobalContext = context; } } }
使用方法:
在MyApplication onInitialize调用ContextUtil.setHapGlobalContext(this)设置全局Context;
调用SystemSettingUtil.getXXX。
注:key常量可使用hdc shell执行以下命令获取。
settings list system
settings list secure
settings list global
代码里怎么区分用户是否调整了系统字体大小设置里【显示大小】?
https://developer.huawei.com/consumer/cn/forum/topic/0202539565144520016?fid=23
(出处: 论坛首页)
解决方案:
private static final String INIT_DPI = "init_dpi"; private static final String DISPLAY_DENSITY_FORCED = "display_density_forced"; SystemSettingUtil.getSecure(INIT_DPI); SystemSettingUtil.getSecure(DISPLAY_DENSITY_FORCED);
display_density_forced为空即显示大小为默认,display_density_forced
“怎么用Data Ability读取系统设置项”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
本文标题:怎么用DataAbility读取系统设置项
文章位置:http://ybzwz.com/article/pchpeo.html