重新启动Android SystemUIService后,如何在不重新启动的情况下刷新墙纸图像? [英] How do I refresh the wallpaper image without reboot after restarting the Android SystemUIService?

查看:108
本文介绍了重新启动Android SystemUIService后,如何在不重新启动的情况下刷新墙纸图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的公司创建一个企业应用程序,该应用程序只能在公司提供的7英寸平板电脑上运行,该平板电脑植根并运行Android 4.2.2。要求是,当员工登录该应用程序时,他们不应能够在退出之前退出应用程序。我可以通过在登录时同时隐藏顶部的系统栏和底部的导航栏,然后在他们注销时再次显示两个栏来实现此目的。执行以下命令:

I'm creating an enterprise app for my company that will only run on a company provided 7" tablet which is rooted and running Android 4.2.2. A requirement is that when the employee logs in to the app, they should not be able to leave the app until they log out. I'm able to achieve this by hiding both the top system bar and bottom navigation bar when they log in and then I show both bars again when they log out. To hide the bars I execute the following command:

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

并再次显示条,我执行以下命令:

and to show the bars again I am execute this command:

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

何时我将条形图隐藏起来,墙纸背景图像被删除了,这很好。当我再次显示条形图时,墙纸图像直到设备重启后才被替换,这是不理想的。

When I hide the bars the wallpaper background image is removed, which is fine. When i show the bars again, the wallpaper image is not replaced until the device reboots which is not ideal.

所以我的问题是这个。 。有人可以告诉我如何在启动SystemUIService后刷新或显示墙纸图像而无需重新启动设备吗?

So my question is this... can anyone tell me how to refresh or show the wallpaper image without needing to reboot the device after I start the SystemUIService?

推荐答案

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

After further investigation i discovered that when i run these commands, the wallpaper only disappears when it was an image and not a live wallpaper or video wallpaper.

我意识到这是非常不常见的情况,但我想我会分享我的解决方案,以防将来可能对其他人有所帮助。我希望有一个我可以运行的命令可以解决此问题,但找不到任何内容,所以我决定以编程方式刷新墙纸。 WallpaperManager目前没有刷新方法,因此我只获取现有的墙纸图像,然后将墙纸设置为该图像。有点hack,但在我看来,这比给用户提供黑色墙纸要好。

I realise that this is quite specific to an uncommon scenario, but I thought I would share my solution in the event that it may help somebody else in the future. I hoped that there was a command that i could run that would resolve this but couldn't find anything so I decided to refresh the wallpaper programmatically. WallpaperManager doesn't have a refresh method at this stage so I just get the existing wallpaper image and then set the wallpaper to that image. A bit of a hack but in my opinion it is better than leaving the user with a black wallpaper.

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 SystemUIService后,如何在不重新启动的情况下刷新墙纸图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆