我正在构建一个启动器,需要访问用户当前的背景壁纸,但每次启动应用程序时都会收到警告W/WallpaperManager: No permission to access wallpaper, suppressing exception to avoid crashing legacy app.
在日志中。
这是我正在使用的代码:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
ImageView imageView = findViewById(R.id.background);
imageView.setImageDrawable(wallpaperDrawable);
此代码返回默认的库存背景图像,而不是我的实际背景图像。我在其他一些主流启动器(Evie、Launchair 等)上注意到了这个问题,但它似乎只发生在我最近更新的 Andorid 8.1 设备上。
进一步深入研究实际的 Android 源代码,我发现了这一点:
if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.O) {
Log.w(TAG, "No permission to access wallpaper, suppressing"
+ " exception to avoid crashing legacy app.");
} else {
// Post-O apps really most sincerely need the permission.
throw e;
}
但我似乎无法找到所需实际许可的参考。
任何帮助表示赞赏!
对于 Api 27 (Android 8.1) 设备,更改targetSdkVersion
到 27 并添加READ_EXTERNAL_STORAGE
清单的权限修复了这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)