Android Question null in Parse uri in 4.4.2

Blue.Sky

Active Member
Licensed User
Longtime User
Hi
I use below Function
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 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
  res = Cursor1.GetString("_data")
  Cursor1.Close
  Return res
 
End Sub
I dont have a problem in all version android but in 4.4.2 when i select image,
it return below path and when parse it,result is null
content://com.android.providers.downloads.documents/document/1492
 

Blue.Sky

Active Member
Licensed User
Longtime User
Which line causes this error?

Why do you need the file path? It is possible that the image doesn't have any path (it can come from a database for example).
return null when use it.
I want to upload any file to server
I can parse uri from content://com.android.providers.documents/document/1492 but not content://com.android.providers.downloads.documents/document/1492
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
Are you uploading the files with http or ftp?
Sorry Erel,it is big project.i dont have any problem in upload
I only have problem in get uri of content://com.android.providers.downloads.documents/document/1492
I have forced use file explorer
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
The correct / recommended way is to work with the InputStream. Don't try to get the file path at all.
I use InputStream but get error that cannot find path.
I put by this topic Erel,I use File explorer
Thank you
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
I assume that you are using ContentChooser. You are using it incorrectly. You do not need to find the file path.

B4X:
Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
  Dim in As InputStream = File.OpenInput(Dir, FileName)
  'work with inputstream.
End If
End Sub
Thank you Erel but in Download folder in android 4.4.2 cannot handle inputstream
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
Which error do you get?
1hukq8.jpg


2n1atdl.jpg
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
Please post the error message from the logs.

I don't think that the error message above can happen from the code in post #8.
Ok please wait to get error and post here
 
Upvote 0
Top