Accessing WallpaperManager in Android 8.1

android wallpaper android-wallpaper

737 观看

1回复

409 作者的声誉

I'm building a launcher and need to access the user's current background wallpaper but every time I launch the app I get the warning W/WallpaperManager: No permission to access wallpaper, suppressing exception to avoid crashing legacy app. in the logs.

Here is the code I'm using:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable wallpaperDrawable = wallpaperManager.getDrawable();

ImageView imageView = findViewById(R.id.background);
imageView.setImageDrawable(wallpaperDrawable);

This code returns the default stock background image rather than my actual background image. I've noticed this problem on a few other mainstream launchers (Evie, Launchair, etc) but it only seems to happen on my recently-updated Andorid 8.1 device.

Digging further into the actual Android Source code, I've found this:

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

But I can't seem to find a reference to the actual permission required.

Any help is appreciated!

作者: Epicality 的来源 发布者: 2017 年 12 月 27 日

回应 1


3

470 作者的声誉

决定

For Api 27 (Android 8.1) devices, changing the targetSdkVersion to 27 and adding the READ_EXTERNAL_STORAGE permission to the manifest fixes this.

作者: lakshman.pasala 发布者: 2017 年 12 月 27 日
32x32