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

Sergio Haurat

Active Member
Licensed User
Longtime User
I have tried to make it work with the examples on the forum and I have not been able to get it to work.

Manifest file:
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="ilogclnt" android:host="open" />
 </intent-filter> )

In Main:

B4X:
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
 
Solution
Source: https://developer.android.com/training/app-links

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:
XML:
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category...

drgottjr

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

Sergio Haurat

Active Member
Licensed User
Longtime User

Attachments

  • frame.png
    frame.png
    1.6 KB · Views: 36
  • IMG_2074.jpeg
    IMG_2074.jpeg
    61.8 KB · Views: 37
Last edited:
Upvote 0

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

  • 3.png
    3.png
    22 KB · Views: 33
  • 2.png
    2.png
    165 KB · Views: 31
Upvote 0

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

https://developer.android.com/training/app-links

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

In the example
JSON:
[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.example",
    "sha256_cert_fingerprints":
    ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"]
  }
}]
 
Last edited:
Upvote 0

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:
B4X:
        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.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
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:
B4X:
        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.

Image 2 shows the installation information, in this case, they are the links associated with the application. This example, WhatsApp Business.
Something changed since version 12 of Android, I think the example you tried was done on an emulator

1717468829345.png
1717468840648.png
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
sorry, i thought we were dealing with qr codes.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Source: https://developer.android.com/training/app-links

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:
XML:
<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" />
    <data android:host="myownpersonaldomain.com" />
</intent-filter>

Android App Links​

Android App Links, available on Android 6.0 (API level 23) and higher, are web links that use the HTTP and HTTPS schemes and contain the autoVerify attribute. This attribute allows your app to designate itself as the default handler of a given type of link. So when the user clicks on an Android App Link, your app opens immediately if it's installed—the disambiguation dialog doesn't appear.

If the user doesn't want your app to be the default handler, they can override this behavior from the app's settings.

The following code snippet shows an example of an Android App Link filter:

XML:
<intent-filter android:autoVerify="true">
    <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" />
    <data android:scheme="https" />

    <data android:host="myownpersonaldomain.com" />
</intent-filter>

Statement List Generator and Tester

Apache folder
1717478701893.png


assetlinks.json file content
1717478800965.png


package_name value from
1717478889009.png


sha256_cert_fingerprints value from
1717478961908.png
1717479059242.png


Manifest editor lines
B4X:
AddActivityText(Main,
<intent-filter android:autoVerify="true">
  <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="*.interlog.com.ar" />
  <data android:scheme="https" android:host="*.interlog.com.ar" />
</intent-filter>)
 
Last edited:
Upvote 0
Solution
Top