我正在构建一个启动器,需要访问用户当前的背景墙纸,但每次启动应用程序时,我都会在日志中收到警告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,Laun椅子等),但它似乎只发生在我最近更新的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;
}但我似乎找不到实际所需权限的引用。
如有任何帮助,我们不胜感激!
发布于 2017-12-28 06:22:39
对于Api 27 (Android8.1)设备,将targetSdkVersion更改为27并将READ_EXTERNAL_STORAGE权限添加到清单可以修复此问题。
https://stackoverflow.com/questions/47995463
复制相似问题