Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. I can't change lock screen wallpaper in my kotlin wallpaper app

I can't change lock screen wallpaper in my kotlin wallpaper app

Scheduled Pinned Locked Moved Android
androidgraphicsannouncement
6 Posts 2 Posters 16 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VipulSh
    wrote on last edited by
    #1

    Here fl_iv is the frame layout containing the imageview which showcases the image. I have set up a button there which allows user to use the image as LOCK SCREEN wallpaper. id of that button is lock_screen. Please try to be descriptive as i am new to this language I tried this code for lock screen but its not working.

    lock_screen.setOnClickListener {
    val wpManager = WallpaperManager.getInstance(this)
    val myBitmap: Bitmap = fl_iv.drawToBitmap()
    try {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    wpManager.setBitmap(myBitmap, null, true, WallpaperManager.FLAG_LOCK)
    }
    else{
    return@setOnClickListener
    }
    } catch (ex: IOException) {
    ex.printStackTrace()

            }
        }
    
    L 1 Reply Last reply
    0
    • V VipulSh

      Here fl_iv is the frame layout containing the imageview which showcases the image. I have set up a button there which allows user to use the image as LOCK SCREEN wallpaper. id of that button is lock_screen. Please try to be descriptive as i am new to this language I tried this code for lock screen but its not working.

      lock_screen.setOnClickListener {
      val wpManager = WallpaperManager.getInstance(this)
      val myBitmap: Bitmap = fl_iv.drawToBitmap()
      try {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
      wpManager.setBitmap(myBitmap, null, true, WallpaperManager.FLAG_LOCK)
      }
      else{
      return@setOnClickListener
      }
      } catch (ex: IOException) {
      ex.printStackTrace()

              }
          }
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      VipulSh wrote:

      but its not working

      Unfortunately that does not explain what your problem is. Please edit your question and explain what happens when you run your code (assuming it is your code, and not something downloaded from the internet).

      V 1 Reply Last reply
      0
      • L Lost User

        VipulSh wrote:

        but its not working

        Unfortunately that does not explain what your problem is. Please edit your question and explain what happens when you run your code (assuming it is your code, and not something downloaded from the internet).

        V Offline
        V Offline
        VipulSh
        wrote on last edited by
        #3

        Yea i tried to write it according to android documentation. It does nothing. Not even an error. It just doesn't do anything. I want to click it and set my bitmap image as lock screen wallpaper but nothing happens. What i should change in it to make it work for me?

        L 1 Reply Last reply
        0
        • V VipulSh

          Yea i tried to write it according to android documentation. It does nothing. Not even an error. It just doesn't do anything. I want to click it and set my bitmap image as lock screen wallpaper but nothing happens. What i should change in it to make it work for me?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Sorry, no idea. The only way to find out what is happening is by using the debugger. Something in your code must be wrong, or using the system in the wrong way.

          V 1 Reply Last reply
          0
          • L Lost User

            Sorry, no idea. The only way to find out what is happening is by using the debugger. Something in your code must be wrong, or using the system in the wrong way.

            V Offline
            V Offline
            VipulSh
            wrote on last edited by
            #5

            It would have been easier if logcat actually declared some error. but as no error is showing up idk whats happening

            L 1 Reply Last reply
            0
            • V VipulSh

              It would have been easier if logcat actually declared some error. but as no error is showing up idk whats happening

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Have you actually stepped through the code in the debugger to see if it does make the call to wpManager.setBitmap? Also why are you not checking the return value from that call to see whether it succeeded or not?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups