Jonathan Twite
Jonathan Twite

Reputation: 952

Android get wallpaper name

I am developing an Android app for our company which sets the wallpaper to a specific company wallpaper every time the phone is booted. It would be preferable to check to see if the wallpaper has been changed rather than running the code to change the wallpaper.

Is there any way to get identifying information (e.g. filename etc.) from the current wallpaper?

WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo();

returns null for wallpaperInfo.

Code for wallpaper change:

public static void setWallpaper(Context context) {

    // Has wallpaper changed?
    if (/*--wallpaperNotChanged--*/) {
        return;
    }

    try {

        // Setup
        Drawable drawable = context.getResources().getDrawable(R.drawable.test);
        DisplayMetrics displayMetrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);

        // Get display sizes
        windowManager.getDefaultDisplay().getMetrics(displayMetrics);

        // Create Bitmap
        Bitmap unscaledWallpaper = BitmapFactory.decodeResource(context.getResources(), R.drawable.test);
        Bitmap wallpaper = Bitmap.createScaledBitmap(unscaledWallpaper, displayMetrics.widthPixels, displayMetrics.heightPixels, true);

        // Set wallpaper
        wallpaperManager.setBitmap(wallpaper);

    } catch (Exception e){
        Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

Upvotes: 1

Views: 907

Answers (2)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

Please read this get-current-wallpaper. And Get current wallpaper absolute path

final Drawable wallpaperManager = wallpaperManager.getDrawable();

For better info you can visit:
https://developer.android.com/reference/android/app/WallpaperInfo.html

Upvotes: 1

Burak Day
Burak Day

Reputation: 959

WallpaperManager API Reference

public WallpaperInfo getWallpaperInfo ()

Here it says:

If the current wallpaper is a live wallpaper component, return the information about that wallpaper. Otherwise, if it is a static image, simply return null.

You must be having a static image wallpaper in your background, not a live one.

Upvotes: 0

Related Questions