Android Question Set bitmap as lockscreen background?

Discussion in 'Android Questions' started by wy328, Oct 10, 2016.

  1. wy328

    wy328 Member Licensed 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 :
    Code:
    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, True2), 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!
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the full error message?
     
  3. wy328

    wy328 Member Licensed User

    Code:
    java.lang.NoSuchMethodException: setBitmap [class android.graphics.Bitmap, class android.graphics.Rect, boolean, int]
    Thank you!
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    API 24 is Android 7.0 not 6.0.
     
  5. wy328

    wy328 Member Licensed User

    Aha, my fault! :oops:
    Is there any other way to do this with out API24?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. tuhatinhvn

    tuhatinhvn Active Member Licensed User

  8. Erel

    Erel Administrator Staff Member Licensed User

    It sets the wallpaper.

    Add this permission to the manifest editor:
    Code:
    AddPermission(android.permission.SET_WALLPAPER)
    Call this method with:
    Code:
    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))
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice