2014-04-04 58 views
2

我正在为我公司创建一个企业应用程序,该应用程序只能运行在7英寸平板电脑上,并且运行Android 4.2.2。需求是当员工登录到应用程序时,他们不应该是可以在应用程序退出之前离开应用程序,我可以通过在登录时隐藏顶部系统栏和底部导航栏来实现此目的,然后在注销时再次显示这两个栏为了隐藏我执行的栏下面的命令:重新启动Android SystemUIService后,如何在不重新启动的情况下刷新壁纸图像?

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

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

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

当我隐藏酒吧墙纸背景图像被删除,这很好。当我再次显示酒吧时,壁纸图像不会被替换,直到设备重新启动,这是不理想的。

所以我的问题是这个......任何人都可以告诉我如何刷新或显示壁纸图像,而无需在启动SystemUIService后重启设备?

回答

2

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

我意识到这是非常特殊的一个不常见的情况,但我想我会分享我的解决方案,如果它可以帮助别人在未来的事件。我希望有一个命令,我可以运行,将解决这个问题,但无法找到任何东西,所以我决定刷新壁纸以编程方式。在这个阶段,WallpaperManager没有刷新方法,所以我只得到现有的壁纸图像,然后将壁纸设置为该图像。有点破解,但在我看来,它比留下黑色壁纸的用户更好。

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; 
} 
+0

将此功能抽象为辅助类时,我发现'wallpaperManager.peekDrawable()'为null。在这种情况下,我将其更改为'wallpaperManager.getDrawable()',它解决了问题。 – Dallas187

+0

你的代码片段工作的很好。在执行相同的操作时,当系统授予su权限来隐藏状态栏时,会显示一个吐司。在我的kiosk模式应用程序中,我想避免它。是否有办法隐藏该吐司好? – Basher51

+0

这款烤面包通常由您安装的SU应用程序控制。其中一些SU应用程序的设置允许您关闭Toast通知。您可以尝试其中的一些内容来查看是否包含此设置,或者您可以在[Google Play]上查看Chainfire的SuperSU应用程序(https://play.google.com/store/apps/details?id=eu .chainfire.supersu) – Dallas187

相关问题