Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. adb shell service call activity 42 s16 com.android.systemui
  2.  
  3. adb shell am startservice -n com.android.systemui/.SystemUIService
  4.  
  5. private void refreshWallpaper()
  6. {
  7. try
  8. {
  9. WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
  10. WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo();
  11.  
  12. // wallpaperInfo is null if a static wallpaper is selected and
  13. // is not null for live wallpaper & video wallpaper.
  14. if (wallpaperInfo == null)
  15. {
  16. // get the existing wallpaper drawable
  17. Drawable wallpaper = wallpaperManager.peekDrawable();
  18.  
  19. // convert it to a bitmap
  20. Bitmap wallpaperBitmap = drawableToBitmap(wallpaper);
  21.  
  22. // reset the bitmap to the current wallpaper
  23. wallpaperManager.setBitmap(wallpaperBitmap);
  24. }
  25. }
  26. catch (Exception e)
  27. {
  28. // TODO: Handle exception as needed
  29. e.printStackTrace();
  30. }
  31. }
  32.  
  33. private static Bitmap drawableToBitmap(Drawable drawable)
  34. {
  35. if (drawable instanceof BitmapDrawable)
  36. {
  37. return ((BitmapDrawable) drawable).getBitmap();
  38. }
  39.  
  40. Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);
  41. Canvas canvas = new Canvas(bitmap);
  42. drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
  43. drawable.draw(canvas);
  44.  
  45. return bitmap;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement