Wallpaper without launcher as form background, how?

JohnK

Active Member
Licensed User
Longtime User
Hi,

I searched the forum, and all I found was how to have a transparent form. This solution is close, but what it leaves me with, is a view of my launcher and all the icons and widgets. I am trying to get a clean form to place my interface on, with the wallpaper as the form background. The closest example I have on my phone is the "Clock" app (CM9), which shows the wallpaper, and only the current time. The next closest thing would be the lock screen.

Anyone know how this is done in B4A?

Thanks in advance.
 

melamoud

Active Member
Licensed User
Longtime User
here it is

to set the activity backgroud just do:
B4X:
activity.SetBackgroundImage(LoadBitmap(File.DirAssets,"bg.png"))

to get wall paper (you need he reflection lib)
B4X:
Sub GetWallpaperBackground As Object
    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", _
        Array As Object(r.GetContext), Array As String("android.content.Context"))
    Dim bg As Object
    bg = r.RunMethod("getDrawable")
    Return bg
End Sub

to save the wallpaper as a file put this in your create sub
B4X:
Dim bg As Object
    bg = GetWallpaperBackground
   'Activity.Background = bg
   Dim Out As OutputStream
   Out = File.OpenOutput(File.DirDefaultExternal, "bg.png", False)
   If bg Is BitmapDrawable Then
      ToastMessageShow("is drawable!",True)
      Dim bd As BitmapDrawable
       bd = bg

   Dim btm As Bitmap
      btm = bd.Bitmap
      btm.WriteToStream(Out, 100, "PNG")      
      Out.Close
   Else
      ToastMessageShow("is NOT drawable!",True)
      Dim bt As Bitmap
      bt = bg
      'Create a mutable Bitmap with Bitmap.InitializeMutable.
      Dim w As Int 'width
      Dim l As Int 'length
      w = bt.Width
      l = bt.Height            
      Dim btm As Bitmap         
      btm.InitializeMutable(w,l) ' todo get layout from device layout ?? or from bg ?
      'Create a Canvas For this Bitmap.
      Dim can As Canvas
      'Draw the drawable with Canvas.DrawDrawable
      Dim DestRect As Rect
      DestRect.Initialize(0,0, w, l)
      can.DrawDrawable(bg,DestRect)
      'Save the Bitmap To a File (Bitmap.WriteToStream)
      btm.WriteToStream(Out, 100, "PNG")
      
   End If
 
Upvote 0

JohnK

Active Member
Licensed User
Longtime User
You can get the wallpaper image as a drawable. I've posted such a code in the forum.
The examples I explicitly mentioned above also support Live Wallpapers. The code I see posted above (thanks) all seems to be for fixed Bitmaps, but I could be wrong.
 
Upvote 0

JohnK

Active Member
Licensed User
Longtime User
OOps.. my bad... found it on a second search through google...:sign0013:
http://www.b4x.com/forum/basic4andr...et-activity-background-current-wallpaper.html
Going off the basic principal of two wrongs make a right, as any programmer knows a double negative becomes a positive, I was right. The code here only returns a static image of the wallpaper, not setting the activity background as a canvas for the live wallpaper to render itself on. Sorry I didn't get to test it sooner, I'm in the middle of a pc rebuild.
 
Upvote 0
Top