2017-12-27 132 views
1

我正在构建一个启动器,需要访问用户的当前背景墙纸,但每次启动应用程序时,我都会在日志中收到警告W/WallpaperManager: No permission to access wallpaper, suppressing exception to avoid crashing legacy app.在Android 8.1中访问WallpaperManager

这里是我使用的代码:

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; 
} 

,但我似乎无法找到所需的实际权限的参考。

任何帮助表示赞赏!

+1

你的目标SDK版本是什么? –

+0

它目前设置为26.我会尝试将其设置为27 – Epicality

+1

是的,尝试将其设置为27,看看是什么行为。 –

回答

1

对于Api 27(Android 8.1)设备,将targetSdkVersion更改为27并将READ_EXTERNAL_STORAGE权限添加到清单可修复此问题。