Android Question video gallery problem

bixmatech

Member
Licensed User
Hi again

I'll explain my video gallery problem

I've two buttons one for "Images Browse" and other for "Videos Browse" , both of them open the gallery.

The problem, when I use my app on Sony Z Ultra (5.0.2) , and browse for videos or images will open "Recent List" , if I browse for images and choose one from that list, will work normally , But if I browse for videos and select one from that list(Recent), will not working ,

But if chose video first from the left list then chose the video will work normally..

this problem just on Sony Z Ultra , but on my Note 4 (6.0.1) , both work normally.

- is there a way to let the video on Z Ultra open directly to video list not to recent list ?
- I need the path because I want to upload the image/video.


B4X:
Sub Button3_Click
    imageIndex = 0
    Chooser.Show("video/*", "Select a video")
End Sub

Sub GetPathFromContentResult(UriString As String) As String
    If UriString.StartsWith("/") Then Return UriString 'If the user used a file manager to choose the image
    Dim Cursor1 As Cursor
    Dim Uri1 As Uri
    Dim Proj() As String = Array As String("_data")
    Dim cr As ContentResolver
    cr.Initialize("")
    If UriString.StartsWith("content://com.android.providers.media.documents") Then
        Dim i As Int = UriString.IndexOf("%3A")
        Dim id As String = UriString.SubString(i + 3)
        Uri1.Parse("content://media/external/images/media")
        Cursor1 = cr.Query(Uri1, Proj, "_id = ?", Array As String(id), "")
    Else
        Uri1.Parse(UriString)
        Cursor1 = cr.Query(Uri1, Proj, "", Null, "")
    End If
    Cursor1.Position = 0
    Dim res As String

    If Cursor1.RowCount > 0 Then
        res = Cursor1.GetString("_data")
    End If
   
    Cursor1.Close
    Return res
End Sub

Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        Dim words() As String = Regex.Split("\/", GetPathFromContentResult(FileName))
        Dim name As String = words(words.Length-1)
        Dim path As String
        Dim i As Int
        For i = 0 To words.Length-2
            path = path & words(i) & "/"
        Next
       
    Else
        ToastMessageShow("Nothing Selectd", True)
    End If
End Sub


the error here :
B4X:
' Cursor1.RowCount  = 0


And i tried this code , instead of the above (but same problem)

B4X:
Sub GetPathFromContentResult(UriString As String) As String
    If UriString.StartsWith("/") Then Return UriString 'If the user used a file manager to choose the image
    Dim Proj() As String
    Proj = Array As String("_data")
    Dim Cursor As Cursor
    Dim r As Reflector
    Dim Uri As Object
    Uri = r.RunStaticMethod("android.net.Uri", "parse", _
      Array As Object(UriString), _
      Array As String("java.lang.String"))
    r.Target = r.GetContext
    r.Target = r.RunMethod("getContentResolver")
    Cursor = r.RunMethod4("query", _
   Array As Object(Uri, Proj, Null, Null, Null), _
   Array As String("android.net.Uri", _
      "[Ljava.lang.String;", "java.lang.String", _
      "[Ljava.lang.String;", "java.lang.String"))
    Cursor.Position = 0
    Dim res As String
    res = Cursor.GetString("_data")
    Cursor.Close
    Return res
End Sub


Thank you ...
 

Attachments

  • 01.jpg
    48.6 KB · Views: 355
  • 02.jpg
    31 KB · Views: 373

bixmatech

Member
Licensed User
Thank you Erel for your answer

I can't get the path of video from Recent List (just on Sony z ultra), so I can't copy it and I don't need to do that , I just need to get the real path (Sdcard/0/DCIM/test.mp4)

Any idea ?

Thanks...
 
Upvote 0

bixmatech

Member
Licensed User

Thank you DonManfred ...

I tried this code to copy the video , But It's not working , Where is the problem ?

B4X:
Sub chooser_Result (Success As Boolean, Dir AsString, FileName AsString)
    Dim out As OutputStream
    Dim input As InputStream
    input = File.OpenInput(Dir , FileName)
    out = File.OpenOutput(File.DirInternal, "Temp.mp4" , False )
    File.Copy2(input, out)
    out.Close
End Sub
 
Last edited:
Upvote 0

bixmatech

Member
Licensed User
Not enough information to help you. What is the error message?

No error message..

sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Done

I added Log("Done") after out.Close

but are you sure there is no another solution from copy the video to other path ?
i tested on Samsung Edge 6 (7.0.0) , but same problem as Sony Z Ultra , just on Android 6 (Note 4) worked perfectly.

Thank you ...
 
Upvote 0

bixmatech

Member
Licensed User
How do you see that it fails to copy the file?

this is the code with logs

B4X:
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
   
    Log("Success = " & Success)
    Log("Dir: " & Dir)
    Log("FileName: " & FileName)
   
    Dim out As OutputStream
    Dim input As InputStream
    input = File.OpenInput(Dir , FileName)
    out = File.OpenOutput(File.DirInternal, "Temp.mp4" , False )
    File.Copy2(input, out)
    out.Close
   
    Log("Done")
End Sub


Logs :
Success = true
Dir: ContentDir
FileName: content://com.android.providers.media.documents/document/video%3A13619
Done

but when I opened the path (Android/data/App Package Name/files/) I just found the databases of the app , but the video I selected from the "Recent List" , not found it
so I think it's failed to copy it or maybe unable to get the real path.

Thank you ...
 
Upvote 0

bixmatech

Member
Licensed User
What is the output of:
B4X:
Log("Done")
Log(File.Size(File.DirInternal, "Temp.mp4"))

Thank you Erel for every things, I was checking on (Android/data/App Package Name/files/) folder, in this case I have to change from DirInternal to DirDefaultExternal to see the file.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…