setup Wallpaper from Bitmap file path - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

setup Wallpaper from Bitmap file path

Demo Code


//package com.java2s;
import java.io.File;
import java.io.IOException;

import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

public class Main {

    public static boolean setupWallpaper(File file, Context context) {
        if (file == null) {
            throw new IllegalArgumentException("file is null");
        }//  w ww  . j  a  v  a2s.  co m

        Bitmap bitmap = BitmapFactory.decodeFile(file.getPath());
        WallpaperManager wallpaperManager = WallpaperManager
                .getInstance(context);
        try {
            wallpaperManager.setBitmap(bitmap);
            return true;
        } catch (IOException e) {
            Log.e("rsmapp", "WallpaperThread:" + e.getMessage());
            e.printStackTrace();
        }
        return false;
    }
}

Related Tutorials