Recent

Author Topic: LAMW - opening URL in external (default) browser stopped working in Android 11  (Read 2087 times)

Manlio

  • Full Member
  • ***
  • Posts: 164
  • Pascal dev
I made an app with LAMW with a button/link that opens a URL in the default browser. This worked fine in Android 9, but I just discovered that since Android 11, it doesn't work any more.

The code which implemented opening the URL is this:

Code: [Select]
    jIntentManager1.SetAction(iaView); 
    jIntentManager1.SetDataUriAsString(url);
    if jIntentManager1.ResolveActivity then
        jIntentManager1.StartActivity();

Android 11 introduced new security requirements, which I researched and modified the manifest file to comply, but it still doesn't work.
I'm attaching the manifest file.

Any help will be greatly appreciated.
manlio mazzon gmail

c4p

  • Full Member
  • ***
  • Posts: 166
I am testing this on Android 12, and this definitely works, you will of course require 'INTERNET' permission in the manifest too, which you have probably done already:

Code: Pascal  [Select][+][-]
  1. jIntentManager1.SetAction('android.intent.action.VIEW');
  2. jIntentManager1.SetMimeType('text/html');
  3. jIntentManager1.SetDataUriAsString('https://www.reuters.com');
  4. jIntentManager1.StartActivity();    

I will say that certain URLs, like Youtube.com will jump out their respectively installed app, so you may also want to set a Browser package so it forces to go to a specific URL rather than an installed default app to apply, entirely up to you though:

Code: Pascal  [Select][+][-]
  1. jIntentManager1.SetPackage('com.brave.browser');
Lazarus 2.0.12 r64642/FPC 3.2.0 LAMW v0.8.6.4 on Windows 10+Linux Mint 21.2, projects mainly built using AppCompat and Gradle.

Manlio

  • Full Member
  • ***
  • Posts: 164
  • Pascal dev
I am testing this on Android 12, and this definitely works, you will of course require 'INTERNET' permission in the manifest too, which you have probably done already:

Code: Pascal  [Select][+][-]
  1. jIntentManager1.SetAction('android.intent.action.VIEW');
  2. jIntentManager1.SetMimeType('text/html');
  3. jIntentManager1.SetDataUriAsString('https://www.reuters.com');
  4. jIntentManager1.StartActivity();    


I tried the above (thank you!) and what happens is that the web page opens within my app - embedded in my app's current view. What I want however is to open the web page externally, in the default web browser, not within my app.

Note:

1. I tried adding <quotes> and <intent-filter> tags to my manifest file, but I was not able to make it work - I'm probably doing it wrong.

2. If I call "if jIntentManager1.ResolveActivity then jIntentManager1.StartActivity() then nothing happens.

3. Could it be that I must do something in the manifest to ensure that ResolveActivity returns true? Something that complies with the new security requirements introduced with Android 11? And if not in the manifest, where?

4. It's ok if e.g. YouTube opens in some other way. I just want to open generic plain web pages in the default browser. I don't know which browser may be installed on the user's device. If I knew it, I guess I could call that. But then again, there must be a way to open generic web pages with the default browser...

manlio mazzon gmail

c4p

  • Full Member
  • ***
  • Posts: 166
I would suggest using the code below in another button OnClick event, isolated from your code, to see if it works, it should open externally of the app in the default chrome browser. Change to whatever browser package you want it to open with, I would then troubleshoot why your code isn't working.
Your manifest file looks OK to me, although guessing you're using an intent somewhere else for the phone state.
Of course, I am testing on Android 12 but I wouldn't have thought there is that much difference between 11 and 12, I may need to check that, but try the below in an OnClick event of a button and see what happens?

Code: Pascal  [Select][+][-]
  1. jIntentManager1.SetAction('android.intent.action.VIEW');
  2. jIntentManager1.SetMimeType('text/html');
  3. jIntentManager1.SetDataUriAsString('https://www.reuters.com');
  4. jIntentManager1.SetPackage('com.android.chrome');
  5. jIntentManager1.StartActivity();    

« Last Edit: October 02, 2023, 02:30:56 pm by c4p »
Lazarus 2.0.12 r64642/FPC 3.2.0 LAMW v0.8.6.4 on Windows 10+Linux Mint 21.2, projects mainly built using AppCompat and Gradle.

Manlio

  • Full Member
  • ***
  • Posts: 164
  • Pascal dev
I found that your code (in your first reply) works well on a physical device (Android 11) i.e. opens the default web browser in a separate app, but on virtual devices (Android Studio) it opens it embedded in the app itself. (But that's already major progress for me, so thanks again)

After further research I found that this behaviour (opening in the app itself) is called Custom Tabs, and it looks like that's what happens in the emulators I used.

https://android-developers.googleblog.com/2015/09/chrome-custom-tabs-smooth-transition.html

I'll write here again when I make further progress.
manlio mazzon gmail

c4p

  • Full Member
  • ***
  • Posts: 166
Ah, useful info, thanks for feeding that back.  :)
Lazarus 2.0.12 r64642/FPC 3.2.0 LAMW v0.8.6.4 on Windows 10+Linux Mint 21.2, projects mainly built using AppCompat and Gradle.

 

TinyPortal © 2005-2018