您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么用Data Ability讀取系統(tǒng)設(shè)置項”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
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調(diào)用ContextUtil.setHapGlobalContext(this)設(shè)置全局Context;
調(diào)用SystemSettingUtil.getXXX。
注:key常量可使用hdc shell執(zhí)行以下命令獲取。
settings list system
settings list secure
settings list global
代碼里怎么區(qū)分用戶是否調(diào)整了系統(tǒng)字體大小設(shè)置里【顯示大小】?
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為空即顯示大小為默認(rèn),display_density_forced<init_dpi顯示大小為小,display_density_forced>init_dpi顯示大小為大,未修改過顯示大小時兩項都為空。
“怎么用Data Ability讀取系統(tǒng)設(shè)置項”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。