Android Question Set bitmap as lockscreen background?

wy328

Member
Licensed User
Longtime User
It seems that on API24, they add a new method to set lock screen background.
https://developer.android.com/reference/android/app/WallpaperManager.html

I've tried the following code on my samsung note5 with android 6.0, but I get a warning said no such method :
B4X:
Dim r As Reflector
r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", Array As Object(r.GetContext), Array As String("android.content.Context"))
r.RunMethod4("setBitmap", Array As Object(Bmp, rc, True, 2), Array As String("android.graphics.Bitmap", "android.graphics.Rect", "java.lang.boolean", "java.lang.int"))

What's wrong with this code? And is there other way to set the lock screen background?
Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It sets the wallpaper.

Add this permission to the manifest editor:
B4X:
AddPermission(android.permission.SET_WALLPAPER)

Call this method with:
B4X:
Dim wallpaper As JavaObject
Dim context As JavaObject
context.InitializeContext
wallpaper = wallpaper.InitializeStatic("android.app.WallpaperManager").RunMethod("getInstance", Array(context))
wallpaper.RunMethod("setBitmap", Array(your bitmap here))
 
Upvote 0
Top