Wallpaper setbitmap displays black screen android

86 views Asked by At

When using serBitmap through WallpaperManager ie., wallpaperManager.setBitmap(wallpaperBitmap); I am getting black screen when new wallpaper been set. How to remove the black screen when transition from old wallpaper to new wallpaper?

From where this black screen been displayed in aosp 10?

Below is the code snippet:

setUserWallpaper(this,"test");

private void setUserWallPaper(final Context context, final String userName) {
        setUserWallpaperRunnable =
            new Runnable() {
                @Override
                public void run() {
                    Log.i(TAG, "setUserWallPaper() run");
                    InputStream in = null;
                    OutputStream out = null;
                    try {
                        in = new BufferedInputStream(
                            context.getContentResolver()
                            .openInputStream(
                                Uri.parse(
                                    "content://test.app.personalization.provider/" +
                                    "wall_paper" +
                                    "?user=" +
                                    userName +
                                    "&encryption=false"))
                            );
                        Bitmap wallpaperBitmap = BitmapFactory.decodeStream(in);
                        if(wallpaperBitmap != null){
                            WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
                            wallpaperManager.setBitmap(wallpaperBitmap);
                        } else {
                            Log.i(TAG, "user wallpaper is null.");
                        }
                        Log.i(TAG, "setUserWallPaper() end");
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        try {
                            if (in != null) {
                                in.close();
                            }
                            if(out != null) {
                                out.close();
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            };
        sUserCustomizeWorker.post(setUserWallpaperRunnable);
    }
1

There are 1 answers

0
Style-7 On

I know this bug. Problem: Bitmap is too big for wallpaper so you have to rescale the bitmap.

Rule: bitmap width < device width * 2 and bitmap height < device height * 2.