Android Question open my app from browser and pass a parameters

Addo

Well-Known Member
Licensed User
Longtime User
i have added manifest like following


B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="myapp" />
</intent-filter>
)


but when i type http://myapp in the browser it does not open the app
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i have added manifest like following
your manifest does not match the url used

for myapp://open.com?str=123
myapp is the scheme
open.com is the host

You can not override the default http scheme as the browser is registered to handle http links.

You need to define your own scheme.

B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "myapp://” -->
<data android:scheme="myapp" android:host="*" />
</intent-filter>
)

Once your app runs it register itself to be responsible for any links starting with "myapp" (instead of "http")


your app will be opened then.

Open a browser on the device and try to open

myapp://fnc1/test=bla/test2=blub

Use / to split the parameters as you need to parse the string by yourself.

B4X:
Sub Activity_Resume
    If Activity.GetStartingIntent = lastintent Then Return
    Dim In As Intent
    In = Activity.GetStartingIntent
    lastintent = In
    Log("--- Intent")
    Log("Action: "&In.Action)
    Log("ExtrasToString: "&In.ExtrasToString)
    If In.ExtrasToString <> "no extras" Then
        ListView1.AddSingleLine(In.ExtrasToString)
        ListView1.AddSingleLine("--- Data")
        Dim data As String = In.GetData
        Dim data As String = In.GetData
        If data <> Null Then
            If data.StartsWith("myapp://") Then
                data = data.SubString(8)
            End If
        End If
        Log("Data:"&data)

        'data = data.re Replace("beka:|/|/","")
        ListView1.AddSingleLine("data="&data)
        If data <> Null Then
            Dim method As String = data.SubString2(0,data.IndexOf("/"))
            Log($"Methodname: ${method}"$)
            ListView1.AddSingleLine($"Methodname: ${method}"$)

            Dim values As List
            values.Initialize
            values = Regex.Split("\/", data)
            If values.Size > 0 Then
                For i = 0 To values.Size-1
                    Dim par As String = values.Get(i)
                    'ListView1.AddSingleLine(values.Get(i))
                    If par.IndexOf("=") > 0 Then
                        Dim revalues() As String = Regex.Split("=",par)
                        ListView1.AddTwoLines("Parameter: "&revalues(0),"Value = "&revalues(1))
                    End If
                Next
            End If
        End If
        If In.ExtrasToString.Contains("no extras") Then
            'No Data
        End If
    End If
End Sub

WhatsApp Image 2019-08-17 at 13.54.39.jpeg
 

Attachments

  • customscheme.zip
    9.5 KB · Views: 200
Last edited:
Upvote 0
Top