gpt4 book ai didi

Android获取壁纸名称

转载 作者:行者123 更新时间:2023-11-30 01:59:37 24 4
gpt4 key购买 nike

我正在为我们公司开发一个 Android 应用程序,每次启动手机时都会将墙纸设置为特定的公司墙纸。最好检查壁纸是否已更改,而不是运行代码来更改壁纸。

有没有办法从当前壁纸中获取识别信息(例如文件名等)?

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

wallpaperInfo 返回 null

壁纸更改代码:

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

最佳答案

请阅读此get-current-wallpaper .和 Get current wallpaper absolute path

final Drawable wallpaperManager = wallpaperManager.getDrawable();

如需更多信息,您可以访问:
https://developer.android.com/reference/android/app/WallpaperInfo.html

关于Android获取壁纸名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31696945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com