简体   繁体   中英

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 (eg 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();
    }
}

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM