gpt4 book ai didi

android - 如何在重启Android SystemUIService后不重启的情况下刷新壁纸图片?

转载 作者:行者123 更新时间:2023-11-29 00:21:24 25 4
gpt4 key购买 nike

我正在为我的公司创建一个企业应用程序,该应用程序只能在公司提供的 7 英寸平板电脑上运行,该平板电脑已获得 root 权限并运行 Android 4.2.2。要求是,当员工登录该应用程序时,他们不应该能够离开应用程序直到他们注销。我可以通过在他们登录时隐藏顶部系统栏和底部导航栏来实现这一点,然后在他们注销时再次显示这两个栏。要隐藏栏我执行以下命令:

adb shell service call activity 42 s16 com.android.systemui

为了再次显示条形图,我执行了这个命令:

adb shell am startservice -n com.android.systemui/.SystemUIService

当我隐藏条形图时,墙纸背景图像被移除,这很好。当我再次显示条形图时,壁纸图像直到设备重新启动才被替换,这并不理想。

所以我的问题是...谁能告诉我如何在启动 SystemUIService 后无需重启设备即可刷新或显示墙纸图像?

最佳答案

经过进一步调查,我发现当我运行这些命令时,壁纸只有在它是图像而不是动态壁纸或视频壁纸时才会消失。

我意识到这对于一个不常见的场景来说是非常具体的,但我想我会分享我的解决方案,以防它在未来对其他人有所帮助。我希望有一个我可以运行的命令可以解决这个问题,但找不到任何东西,所以我决定以编程方式刷新墙纸。 WallpaperManager 在这个阶段没有刷新方法,所以我只获取现有的墙纸图像,然后将墙纸设置为该图像。有点 hack,但在我看来,这比给用户留下黑色壁纸要好。

private void refreshWallpaper() {
try {
WallpaperManager wallpaperManager =
WallpaperManager.getInstance(context);
WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo();

// wallpaperInfo is null if a static wallpaper is selected and
// is not null for live wallpaper & video wallpaper.
if (wallpaperInfo == null) {
// get the existing wallpaper drawable
Drawable wallpaper = wallpaperManager.peekDrawable();

// convert it to a bitmap
Bitmap wallpaperBitmap = drawableToBitmap(wallpaper);

// reset the bitmap to the current wallpaper
wallpaperManager.setBitmap(wallpaperBitmap);
}
} catch (Exception e) {
// TODO: Handle exception as needed
e.printStackTrace();
}
}

private static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}

Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);

return bitmap;
}

关于android - 如何在重启Android SystemUIService后不重启的情况下刷新壁纸图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22856662/

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