简体   繁体   English

Android-如何获取当前的墙纸名称

[英]Android - How to get current wallpaper name

I'm developing an application that sets wallpapers from com.android.launcher3 package drawable resources. 我正在开发从com.android.launcher3包可绘制资源中设置墙纸的应用程序。 At some point I need to check if the wallpaper is set correctly so I can move on to other step. 在某个时候,我需要检查墙纸是否设置正确,以便继续进行其他步骤。

After some research in SO and googling, I wasn't able to find any information about getting current wallpaper name. 经过对SO和谷歌搜索的研究后,我无法找到有关获取当前壁纸名称的任何信息。

Here is how I set the drawable which I have no problem: 这是我没有问题的设置可绘制对象的方法:

try {
        WallpaperManager wallpaper_manager = WallpaperManager.getInstance(m_context);

        Resources res       = m_context.getPackageManager().getResourcesForApplication("com.android.launcher3");
        int drawable_id     = res.getIdentifier(wallpaper_name, "drawable", "com.android.launcher3");
        Drawable drawable   = res.getDrawable(drawable_id, null);

        if(drawable != null) {
            wallpaper_manager.setBitmap(((BitmapDrawable)drawable).getBitmap());
        }

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

I can get the current wallpaper as drawable as well: 我也可以将当前墙纸设为可绘制的:

WallpaperManager wallpaper_manager = WallpaperManager.getInstance(m_context);
Drawable drawable                  = wallpaper_manager.getDrawable();

but I haven't managed to get current wallpaper name. 但我还没有获得当前的墙纸名称。

I need help. 我需要帮助。

Thanks in advance. 提前致谢。

I would try this two options: 我会尝试这两种选择:

1. Using wallpaperManager 1.使用wallpaperManager

You shouold be able to get the information using this: 您应该能够使用以下方法获取信息:

wallpaperManager.getWallpaperInfo();

This will return a WallpaperInfo object which contains all the data about the wallpaper. 这将返回一个WallpaperInfo对象,其中包含有关墙纸的所有数据。

More information https://developer.android.com/reference/android/app/WallpaperManager.html 更多信息https://developer.android.com/reference/android/app/WallpaperManager.html

2. Getting the drawable file 2.获取绘图文件

You can also try to get the URI of the drawable like this: 您也可以尝试获取可绘制对象的URI,如下所示:

String imageUri = "drawable://" + R.drawable.image;

And get the file name from there. 并从那里获取文件名。

Hope it helps you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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