private void cw() {
    try {
            WallpaperManager localWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
            Display display = getWindowManager().getDefaultDisplay();
            Point size = new Point();
            try {
                if (VERSION.SDK_INT >= 11) {
                    display.getSize(size);
                    this.mW = size.x;
                    this.mH = size.y;
                } else {
                    this.mW = display.getWidth();
                    this.mH = display.getHeight();
                }
            } catch (Exception e) {
                Toast.makeText(this, "Wallpaper has been set not1.", Toast.LENGTH_SHORT).show();

            }
            Bitmap localBitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), this.cW[this.i]), this.mW, this.mH, true);
            localWallpaperManager.setWallpaperOffsetSteps(1.0f, 1.0f);
            localWallpaperManager.suggestDesiredDimensions(this.mW, this.mH);
            try {
                localWallpaperManager.setBitmap(localBitmap);
                Toast.makeText(this, "Wallpaper has been set successfully.",0).show();
            } catch (IOException e2) {
                Toast.makeText(this, "Wallpaper has been set not2.", Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e3) {
            Toast.makeText(this, "Wallpaper has been set not3.", Toast.LENGTH_SHORT).show();
        }
    }
-4
Akshar Gabani 10 Agustus 2017, 12:46

1 menjawab

Coba kode ini.

        bitmap1 = BitmapFactory.decodeFile(ImgPath.getAbsolutePath());

        displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

        width = displayMetrics.widthPixels;
        height = displayMetrics.heightPixels;
        bitmap2 = Bitmap.createScaledBitmap(bitmap1, width, height, false);

        wallpaperManager = WallpaperManager.getInstance(PagerActivity.this);
        try {
            wallpaperManager.setBitmap(bitmap2);
            wallpaperManager.suggestDesiredDimensions(width, height);
            Utils.showToastShort("WallPaper Set !", PagerActivity.this);

        } catch (IOException e) {
            e.printStackTrace();
        }
0
Divyesh Patel 10 Agustus 2017, 09:51