Android Question Refresh Gallery

Discussion in 'Android Questions' started by AndOrNot, Aug 23, 2016.

  1. AndOrNot

    AndOrNot Well-Known Member Licensed User

    Hi all, i've an application that download different images (with ImageDownloader service from @Erel), and i want after download image to open gallery to give user possibility to set image as wallpaper.
    But after download image, gallery will not refresh itself. I tried This code but for me doesn't work, nothing appear (s6 edge, android 6.0.1)
    Thanks for any help
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    ImageDownloader doesn't save the images. Are you sure that you are saving the images correctly?

    Do a simple test where you copy an image from the assets folder to File.DirRootExternal and then call the code that scans the file. See whether the image is now listed or not.
     
  3. AndOrNot

    AndOrNot Well-Known Member Licensed User

    Yes, i'm sure, i edited image download to save image with the following code:
    Code:
    Sub Save (bitmap As Bitmap , name As String)
        
    If Not(File.Exists(File.DirRootExternal,"XOI Official")) Then File.MakeDir(File.DirRootExternal,"XOI Official")
        
    Dim out As OutputStream
        out = 
    File.OpenOutput(File.DirRootExternal & "/XOI Official",name,False)
        
    bitmap.WriteToStream(out,100,"PNG")
        out.Close
    End Sub
    After save it, i can see image with QuickPic and FileExplorer. I also check if it exits and it exits successfull, but when i try to open with gallery it doesn't recognize it
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It works here with this code:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    File.Copy(File.DirAssets, "asteroids.png"File.DirRootExternal, "asteroids.png")
       ForceGallery(
    File.DirRootExternal, "asteroids.png")
    End Sub

    Sub ForceGallery (Dir As String, FileName As String)
      
    Dim Phone As Phone
      
    If Phone.SdkVersion<19 Then
      
    Dim i As Intent
      i.Initialize(
    "android.intent.action.MEDIA_MOUNTED""file://" & File.Combine(Dir, FileName))
      
    Phone.SendBroadcastIntent(i)
      
    Else
      
    Dim context As JavaObject
      context = context.InitializeStatic(
    "anywheresoftware.b4a.BA").GetField("applicationContext")
      
    Dim paths() As String = Array As String(File.Combine(Dir,FileName)) 'files to scan
      Dim mediaScanner As JavaObject
      mediaScanner.InitializeStatic(
    "android.media.MediaScannerConnection")
      mediaScanner.RunMethod(
    "scanFile"Array As Object(context, paths, NullNull))
      
    End If
    End Sub
     
    MarcoRome, DonManfred, Devv and 2 others like this.
  5. AndOrNot

    AndOrNot Well-Known Member Licensed User

    Yes, thanks, i did not understand code, i thought that force gallery also open file, but it doesn't. Sent intent after it and it works
     
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