How to get android lock screen wallpaper?

前端 未结 3 1490
时光取名叫无心
时光取名叫无心 2021-01-02 16:51

I use the code below to retrieve the android lock screen wallpaper on an android 8.1 phone:

WallpaperManager manager = WallpaperManager.getInstance(getActivi         


        
3条回答
  •  清酒与你
    2021-01-02 17:26

    If no lock-specific wallpaper has been configured for the given user, then this method will return null when requesting FLAG_LOCK rather than returning the system wallpaper's image file.

    Are you sure you have a valid lock screen wallpaper set for the current user?

     /**
         * Get an open, readable file descriptor to the given wallpaper image file.
         * The caller is responsible for closing the file descriptor when done ingesting the file.
         *
         * 

    If no lock-specific wallpaper has been configured for the given user, then * this method will return {@code null} when requesting {@link #FLAG_LOCK} rather than * returning the system wallpaper's image file. * * @param which The wallpaper whose image file is to be retrieved. Must be a single * defined kind of wallpaper, either {@link #FLAG_SYSTEM} or * {@link #FLAG_LOCK}. * * @see #FLAG_LOCK * @see #FLAG_SYSTEM */ public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which) { return getWallpaperFile(which, mContext.getUserId()); }

    There is a similar function in WallpaperManager openDefaultWallpaper in that if you want LOCK-SCREEN wallpaper you get null, always, as According to the code Factory-default lock wallpapers are not yet supported.

    So in your case maybe you haven't set the Lock-Screen wallpaper. Just to test, Download any wallpaper app, and try to set a wallpaper, then use your earlier code, to get it.

    /**
         * Open stream representing the default static image wallpaper.
         *
         * If the device defines no default wallpaper of the requested kind,
         * {@code null} is returned.
         *
         * @hide
         */
        public static InputStream openDefaultWallpaper(Context context, @SetWallpaperFlags int which) {
            final String whichProp;
            final int defaultResId;
            if (which == FLAG_LOCK) {
                /* Factory-default lock wallpapers are not yet supported
                whichProp = PROP_LOCK_WALLPAPER;
                defaultResId = com.android.internal.R.drawable.default_lock_wallpaper;
                */
                return null;
            }
    

    You can check the code at : http://androidxref.com/8.1.0_r33/xref/frameworks/base/core/java/android/app/WallpaperManager.java#openDefaultWallpaper

提交回复
热议问题