如果当前是U0用户(系统用户)下面的Context,想要获取当前用户的Context(比如U10),可以尝试下面的方法:
private Context getContextForForegroundUser() {
try {
return mContext.createPackageContextAsUser(mContext.getPackageName(), /* flags= */
0, UserHandle.of(ActivityManager.getCurrentUser()));
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
}