Android Question SOLVED: Run the app from a custom URL (android:scheme / android:host)

I have tried to make it work with the examples on the forum and I have not been able to get it to work.

AddActivityText(Main,      )
Sub Activity_Create(FirstTime As Boolean) Dim pm As B4XPagesManager pm.Initialize(Activity) Dim i As Intent = Activity.GetStartingIntent If i <> Null Then Dim data As String = i.GetData If data <> Null Then If data.StartsWith("ilogclnt://open") Then Log("Aplicación abierta desde el QR con URL personalizada") End If End If End If End Sub

Sergio Haurat

Web links​

Web links are deep links that use the HTTP and HTTPS schemes. On Android 12 and higher , clicking a web link (that is not an Android App Link) always shows content in a web browser. On devices running previous versions of Android, if your app or other apps installed on a user's device can also handle the web link, users might not go directly to the browser. Instead, they'll see a disambiguation dialog similar to the one that appears in figure 2.

The following code snippet shows an example of a web link filter:

drgottjr

Expert
Licensed User Longtime User works for me. post the qr code

"A little kindness - as little as required by applicable law."
"It can't hurt to read the thread before replying."
"Show code; code always does what you tell it to do, not always what you tell us it does."

Sergio Haurat

Active Member
Licensed User Longtime User works for me. post the qr code

Device Motorola 30 Pro

Attachments

1.6 KB · Views: 69 IMG_2074.jpeg 61.8 KB · Views: 75 Last edited: Jun 4, 2024

drgottjr

Expert
Licensed User Longtime User

sorry, i don't follow what your image #1 has to do with #2. when i scan your barcode, it launches your test. see my attached. i'm sure you know that following qr code links is not necessarily something that happens automatically. i'm not sure how you are expecting some things to happen. in any case, your qr code can launch your app.

Attachments

22 KB · Views: 67 165 KB · Views: 63

"A little kindness - as little as required by applicable law."
"It can't hurt to read the thread before replying."
"Show code; code always does what you tell it to do, not always what you tell us it does."

Sergio Haurat

Active Member
Licensed User Longtime User

Sorry for the confusion, image 2 shows that the app does not have any default URL settings. Neither in debug mode nor in release mode.

I open the camera, it reads the QR and sees it as text. I don't know if it's a device issue (Motorola 30 Pro) or something is missing. The Android version on the physical device is 13

Since version 12 something changed, you have to generate a json and add it to a folder with a specific file

In the example

Last edited: Jun 4, 2024

drgottjr

Expert
Licensed User Longtime User

. image 2 shows that the app does not have any default URL settings. Neither in debug mode nor in release mode.

i have no idea what that means. let's just assume we can dismiss image 2 as irrelevant.

if you're going to use a qr code to launch an app, you need an app to scan the code and to handle an intent to launch an app. it looks like you're relying on your default camera app to handle that. that could be a problem. first, device manufacturers are responsible for their own default camera app. that would include its various features.
in my case (i use google pixel devices), the default camera app has a setting to allow qr codes with a url to launch the default action for such qr codes. that action being to launch the default web browser. to repeat, in the case of pixel devices, the user has to activate that behavior in the app's settings. i would assume the case is similar for your device. the bad news is that your custom url will probably not be recognized as something it can handle. this means you will need an app which can scan and decode a qr code and then try to launch any app which knows how to respond to the custom url intent filter. you have the second part, but maybe not the first part.
i have both parts, so when i scan your qr code (or the one i generated myself), it launches your app. since the url's in most qr codes are designed to launch web browsers, you need one that can launch any url (or at least try). if you pick a simple qr code scanner from among the many available on the forum, you should be able to modify it to run an intent whose scheme is your custom url:

 Dim intent As Intent intent.Initialize(intent.ACTION_VIEW, "ilogclnt://open") StartActivity(intent)

qr codes don't automatically do anything. and applications that scan and decode them don't automatically do anything with them. and those that can recognize url's don't necessarily recognize any beyond a list of generally recognized schemes (eg, http(s),ftp,email,geo,sms, . ) if you want to launch your custom url from a qr code, you need to do that yourself.

the applinks reference may not have anything to do with qr codes.

"A little kindness - as little as required by applicable law."
"It can't hurt to read the thread before replying."
"Show code; code always does what you tell it to do, not always what you tell us it does."