Setup SharedPreferences in credential encrypted storage are not available until after user is unloc

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kongbaidepao/article/details/84032276
Caused by: java.lang.IllegalStateException: SharedPreferences in credential encrypted storage are not available until after user is unlocked
 08:08:00.310  5652  5652 E AndroidRuntime:        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:387)
 08:08:00.310  5652  5652 E AndroidRuntime:        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:372)
 08:08:00.310  5652  5652 E AndroidRuntime:        at android.content.ContextWrappe

https://developer.android.google.cn/  
https://source.android.google.cn/
https://developer.android.google.cn/training/articles/direct-boot

访问设备加密存储

要访问设备加密存储,请通过调用 Context.createDeviceProtectedStorageContext() 创建另一个 Context 实例。使用此上下文执行的所有存储 API 调用均访问设备加密存储。 以下示例访问设备加密存储并打开现有应用数据文件:

Context directBootContext = appContext.createDeviceProtectedStorageContext();
// Access appDataFilename that lives in device encrypted storage
FileInputStream inStream = directBootContext.openFileInput(appDataFilename);
// Use inStream to read content...

仅针对在“直接启动”模式下必须可访问的信息使用设备加密存储。请勿将设备加密存储用作通用加密存储。对于专有用户信息,或在“直接启动”模式下不需要的加密数据,请使用凭据加密存储。

猜你喜欢

转载自blog.csdn.net/kongbaidepao/article/details/84032276