Recent

Author Topic: How to download a file from web page displayed by jWebView  (Read 11405 times)

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: How to download a file from web page displayed by jWebView
« Reply #75 on: June 10, 2023, 02:44:44 pm »
Hi, @c4p!

I have not enough words in my poor pidgin English to thank you! But I can say with confidence that your heroic efforts will contribute to an initiative on biodiversity information outreach and, as a consequence, help our (the humankind, or the most rational fraction of it) efforts towards saving what is still possible...

With warmest regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: How to download a file from web page displayed by jWebView
« Reply #76 on: June 10, 2023, 02:48:08 pm »
Hi, @c4p!

I just tried this...

Code: Pascal  [Select][+][-]
  1. const
  2.   dirOutput = 'Android/data/user/0/org.lamw.appname/files ';

(where appname is the name of my app)

And then in the body of the procedure...

Code: Pascal  [Select][+][-]
  1. if not DirectoryExists(dirOutput) then CreateDir(dirOutput);

Perhaps it is needless to say that this also did not work and no directory has been created.

With warmest regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

c4p

  • Full Member
  • ***
  • Posts: 166
Re: How to download a file from web page displayed by jWebView
« Reply #77 on: June 10, 2023, 03:49:58 pm »
I have had a play, downloaded file to project folder using the dirInternalAppStorage/Download path, but there is an issue launching an application using the intent (StartDefaultActivityForFile or JintentManager, can open browser fine, just not other apps, probably permissions), I will look into this more and get back to you, heading out right now, but will have a look when I get back.
« Last Edit: June 10, 2023, 03:56:08 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.

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: How to download a file from web page displayed by jWebView
« Reply #78 on: June 10, 2023, 03:57:58 pm »
Him @c4p!

Thank you very much!!!

With warmest regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

c4p

  • Full Member
  • ***
  • Posts: 166
Re: How to download a file from web page displayed by jWebView
« Reply #79 on: June 11, 2023, 12:01:24 am »
I can get it to open another app like Google Drive etc using the package name, but does not seem to want to use the file even with GetFileUri() via jDownloadManager, below code is just an example to launch another app, will launch Google Drive.....HasLaunchIntentForPackage was missing from previous examples, it will not open without this....did you ever get an app to launch using the app on Android 10 before?

Code: Pascal  [Select][+][-]
  1.     jIntentManager1.SetAction(iaView);
  2.     jIntentManager1.HasLaunchIntentForPackage('com.google.android.apps.docs');
  3.     jIntentManager1.SetPackage('com.google.android.apps.docs');
  4.     jIntentManager1.StartActivity();

I did try via jDownloadManager/jBroacastReceiver method but still could not get to open the file.

Code: Pascal  [Select][+][-]
  1.     jIntentManager1.SetAction(iaView);
  2.     jIntentManager1.HasLaunchIntentForPackage('com.google.android.apps.docs');
  3.     jIntentManager1.SetPackage('com.google.android.apps.docs');
  4.     jIntentManager1.SetDataAndType(jDownloadManager1.GetFileUri(),'application/pdf');
  5.     jIntentManager1.StartActivity();  

Fairly sure StartDefaultActivityForFile is not supported on Android 10 based on what I can see anyway, I suspect it's using Java code for Android 11+?
This is an issue specific to Android 10, opening a file using StartDefaultActivityForFile works perfect for me in Android 12.....I don't think I can fix this on Android 10, weirdly, when I use the intent code above it doesn't work in Android 12, but StartDefaultActivityForFile does.
Maybe @jmpessoa can help?
« Last Edit: June 11, 2023, 12:03:17 am 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.

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: How to download a file from web page displayed by jWebView
« Reply #80 on: June 11, 2023, 01:31:47 am »
Hi, @c4p!

I am sad about the bad news, but not surprised.

Quote
did you ever get an app to launch using the app on Android 10 before?

No, I did never attempted this before.

Quote
Fairly sure StartDefaultActivityForFile is not supported on Android 10 based on what I can see anyway

It is what seems... But what to say of a web browser in the device being able to download and open a file?  :(

For example, try the following on your mobile device (running either Android 10 or 12):

  • Open the default browser and visit the address: http://biotupe.org/test/

  • Click on one of the linked files - in my device, the file is downloaded by the browser (to the main sotrage Downloads folder) and then opened in the associated app.

In fact, this behaviour was just what I wanted to mimic in my app!

Quote
Maybe @jmpessoa can help?

Since he is the developer of LAMW, if he cannot help, who will? Unfortunately, he has been conspicuous by his absence.

With warmest regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

c4p

  • Full Member
  • ***
  • Posts: 166
Re: How to download a file from web page displayed by jWebView
« Reply #81 on: June 11, 2023, 02:06:22 pm »
jmpessoa should be able to help and is very knowledgeable, I'm confident he can fix this.
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.

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: How to download a file from web page displayed by jWebView
« Reply #82 on: June 11, 2023, 03:23:42 pm »
Hi, @cp4!

I am surely confident he is working around the clock to solve this vexing problem, which anyway may seriously impair the more widespread use of LAMW.

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

jmpessoa

  • Hero Member
  • *****
  • Posts: 2317
Re: How to download a file from web page displayed by jWebView
« Reply #83 on: June 14, 2023, 11:37:31 pm »
Quote
I am surely confident he is working around the clock....

No. File manipulation on android has become very complex... varying with each version and becoming more and more restrictive..... we need to be always studying and looking for new solutions (that meet different versions).... but for that we need a lot of free time... and now I don't have it.... due to the pressure of my professional activities....
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: How to download a file from web page displayed by jWebView
« Reply #84 on: June 15, 2023, 09:37:33 pm »
Hi, @jmpessoa!

I cannot believe the problem is with this or that Android version, because I am using two devices with different versions (5.5.1 and 10) and in both I have problems with opening files. Therefore, the OS version cannot be the single issue at stake.

Anyway, I will keep trying to solve the problem using LAMW. I have spent some time attempting to re-write the app with Delphi 11.3 to no avail! Even the most basic features which I already have in my LAMW app (as a beautiful overflowing menu) I could not implement in Delphi and FireMonkey! Not to mention that the Delphi IDE is ugly and confuse if compared to that of Lazarus IDE! In short, I firmly believe that LAMW is a great tool for developing Android apps in Object Pascal, much better in fact than Delphi & FireMonkey!

Meanwhile, my app is already 99% complete and I will release at as it is. Users may have been able to download the files in Excel and PDF formats and open then with the proper apps in their devices, from the file manager.

Best regards,

« Last Edit: June 15, 2023, 10:23:59 pm by maurobio »
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

 

TinyPortal © 2005-2018