Android Question Get the Path from assosiated File

DataProtec

Member
Licensed User
How can i get the Path from a assosiated file with my App
If i tap on a file in Download my App comes up and i have
B4X:
 Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim In As Intent = Activity.GetStartingIntent  
    Dim Parametri As String = In.GetData
    If Parametri<>Null Then
In Parametri i get "Parametri = content://com.android.externalstorage.documents/document/primary%3ADownload%2Fconf.dpn"
How can i extract the Path from this String, thats my problema, and get permission to Read this file
 

DonManfred

Expert
Licensed User
Asuming you have successfully implemented Runtimepermissions in your starter service

B4X:
    Log(In)
    Log(In.ExtrasToString)
    If In.Action = "android.intent.action.VIEW" Then
        Dim Params As String = In.GetData
        Log(Params)
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
            Dim content As List = File.ReadList("ContentDir",Params)
            If content <> Null And content.IsInitialized And content.Size>0 Then
                Log(content.Size)
                Log(content)
            End If
        End If
    End If
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(Intent) Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=b4a.example3/.main }
no extras
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
(Intent) Intent { act=android.intent.action.VIEW dat=file:///storage/4AFA-61CB/conf.dpn typ= flg=0x10000000 cmp=b4a.example3/.main }
no extras
file:///storage/4AFA-61CB/conf.dpn
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
1
(ArrayList) [testtext :-)]
** Activity (main) Resume **
the content of the conf.dpn is one line
 

DonManfred

Expert
Licensed User
In Parametri i get "Parametri = content://com.android.externalstorage.documents/document/primary%3ADownload%2Fconf.dpn"
how do you get this content uri? If i try it here, app has targetsdk set to 26 and i open a dpn file using ES File Exlorer and i get the uri like
file:///storage/4AFA-61CB/conf.dpn. Even if this a file in a path on my external SDCard. I am using this in a app which has implemented also the external storage class. Maybe this is the difference. I´m not sure why you get a com.android.externalstorage.documents/document uri...

i would like to reproduce it here. Can you show me the way you go on the device?
 

DataProtec

Member
Licensed User
Yes of course,in Log("Parametri = " & Parametri) i get Parametri = content://com.android.externalstorage.documents/document/primary%3ADownload%2Fconf.dpn
I open the App, then tap on the file and get this Output
as you can see in the image
, check the attached file
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
 
    '**************************************
    Dim In As Intent = Activity.GetStartingIntent
    Dim Parametri As String = In.GetData
    If Parametri<>Null Then
        ' Apertura parametri
    Log("Parametri = " & Parametri)
        Activity.LoadLayout("print")
        'LabelInfo.Text="Print file: " & Parametri
    '*****************************************************
       Else
        Log("Apertura App")
    Activity.LoadLayout("main")
    End If
End Sub
 

Attachments

DataProtec

Member
Licensed User
Hi DonManfred
The code above is not working, but dosen't matter
What we did before with the Permissions is working fine and does the same.
If i tap the file it opens the App and get the required Information and save this in a different place.
Exactly what i need, now need to add to the final Project, still testing in Test Envirement.
Thanks for you help
 
Top