您好,登錄后才能下訂單哦!
本篇內容介紹了“怎么用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<init_dpi顯示大小為小,display_density_forced>init_dpi顯示大小為大,未修改過顯示大小時兩項都為空。
“怎么用Data Ability讀取系統設置項”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。