Android Question Read file with custom extension

Sergey_New

Well-Known Member
Licensed User
Longtime User
I read almost the entire forum, but I still couldn't find solutions on how to read a text file with the ".ged" extension, when a file is selected by the device's file manager.
I have to repeat the question again.
I found several manifest examples. For example:
B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.ged" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.ged" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.ged" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.ged" />
<data android:mimeType="*/*" />
</intent-filter>)
None of the examples set the default value in the application settings.
Although the application is launched for the first time with the option to select "always" or "only now", it is impossible to change this choice later.
I wonder where these settings are saved?
Even if I delete the application and reinstall it, the device does not offer to make a choice.
If there is another application on the device for reading such files, then when you delete one of them, the remaining application will also read the file without the ability to change the choice.
What can be done?
And another question:
How can I find out the file name and path in the given example?
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim In As Intent = Activity.GetStartingIntent 
    Dim Parametri As String = In.GetData
    If Parametri<>Null Then
        Activity.LoadLayout("print")
        LabelInfo.Text="Print file: " & Parametri
    Else
        Activity.LoadLayout("main")
    End If
End Sub
I have attached an example.
 

Attachments

  • test_ged.zip
    3.4 KB · Views: 16
Last edited:

Sergey_New

Well-Known Member
Licensed User
Longtime User
I did it like this:
B4X:
Sub Activity_Resume
    Dim intent As Intent = Activity.getstartingintent
    Dim uri As String = intent.GetData
    lbl2.Text=uri
    If uri <> Null Then
        Dim n As Int=uri.LastIndexOf("/")
        Dim fn As String=uri.SubString(n+1)
        lbl.Text=fn
        Dim n1 As Int=uri.LastIndexOf("/storage")
        Dim p As String=uri.SubString2(n1,n+1)
        Dim myFolder As String=File.DirRootExternal & "/Gedcom"
        Try
            File.Copy(p,fn,myFolder,fn)
            lbl2.Text="Copy true"
        Catch
            lbl2.Text="Copy false"
            Log(LastException)
        End Try
    End If
End Sub
Everything works. If the name of the folder from which you need to copy is in Cyrillic, its name is not identified. How can I fix it?
 
Upvote 0
Top