Recent

Author Topic: LAMW how to get html content from a webview component [SOLVED]  (Read 2147 times)

Segator

  • Jr. Member
  • **
  • Posts: 98
    • https://github.com/Nenirey
Hi all and thanks for the lamw project, great job, i know about jhttpclient component but it not support javascript and other dinamic thinks required for some sites, so the webview components is the best way to show html content, but i can't get the information inside it, i make some search on google and found https://stackoverflow.com/questions/8200945/how-to-get-html-content-from-a-webview but i can implement in Pascal, i try to make a wrapper in lamw but is a hard function to start learning the lamw bridge, exits other method to obtain this information @jmpessoa  ?
« Last Edit: August 18, 2020, 02:01:20 pm by Segator »
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

jmpessoa

  • Hero Member
  • *****
  • Posts: 1623
Re: LAMW how to get html content from a webview component
« Reply #1 on: August 16, 2020, 02:43:14 am »
Quote
it, i make some search on google and found https://stackoverflow.com/questions/8200945/how-to-get-html-content-from-a-webview
Did you manage to draw any conclusions from this discussion... ;D

Quote
i try to make a wrapper in lamw but is a hard function to start learning the lamw bridge...

Do a Pascal function/method wrapper from an java API/method is very easy... [I can help...]

In fact, LAMW generates the code for you!
"Tools" -> "[LAMW]..." --> "New jComponent Create" --> [TAB] Help
« Last Edit: August 16, 2020, 03:10:26 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Segator

  • Jr. Member
  • **
  • Posts: 98
    • https://github.com/Nenirey
Re: LAMW how to get html content from a webview component
« Reply #2 on: August 16, 2020, 05:58:10 am »
Hi jmpessoa,
Quote
Did you manage to draw any conclusions from this discussion... ;D
yes, the only way to access to the html content is executing a javascript funcion to obtain the source and webview component support the EvaluateJavascript function but is no wrapper in the lamw component,
Quote
Do a Pascal function/method wrapper from an java API/method is very easy... [I can help...]
i try to do but the pascal code is not the problem, the java code is, i can send you the changes and you can help me where i mistake   :-[
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

jmpessoa

  • Hero Member
  • *****
  • Posts: 1623
Re: LAMW how to get html content from a webview component
« Reply #3 on: August 16, 2020, 06:35:41 am »
Quote
i can send you the changes and you can help me where i mistake   :-[

Ok. Send me, your java code!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Segator

  • Jr. Member
  • **
  • Posts: 98
    • https://github.com/Nenirey
Re: LAMW how to get html content from a webview component
« Reply #4 on: August 16, 2020, 05:58:16 pm »
wheel this is the change in jWebView.java:
Code: Pascal  [Select][+][-]
  1. public String callEvaluateJavascript(string _jscode){
  2.                this.evaluateJavascript(_jscode, new ValueCallback<String>(){
  3.                @Override
  4.                public void onReceiveValue(String s){
  5.                       return s;
  6.                }
  7.         });
  8.         }
And_jni_Bridge.pas:
Code: Pascal  [Select][+][-]
  1.  function jWebView_EvaluateJavaScript(env: PJNIEnv; _jwebview: JObject; _jscode:string):string;
  2. var
  3.   jParams: array[0..0] of jValue;
  4.   jMethod: jMethodID;
  5.   jCls: jClass;
  6.   _jString: jString;
  7. begin
  8.   jParams[0].l:= env^.NewStringUTF(env, PChar(_jscode));
  9.   jCls:= env^.GetObjectClass(env, _jwebview);
  10.   jMethod:= env^.GetMethodID(env, jCls, 'callEvaluateJavascript', '()S');
  11.   //env^.CallVoidMethodA(env, _jwebview, jMethod, @jParams);
  12.   _jString   := env^.CallObjectMethodA(env,_jwebview, jMethod, @jParams);
  13.   Result    := string( env^.GetStringUTFChars(Env,_jString,@jParams) );
  14.   env^.DeleteLocalRef(env, jParams[0].l);
  15.   env^.DeleteLocalRef(env, jCls);
  16. end;
Laz_And_Controls.pas:
Code: Pascal  [Select][+][-]
  1. function jWebView.EvaluateJavascript(_jscode: string):string;
  2. begin
  3.   //in designing component state: set value here...
  4.   if FInitialized then
  5.      result:=jWebView_EvaluateJavaScript(FjEnv, FjObject, _jscode)
  6.   else
  7.      result:='';
  8. end;
i attached the 3 files in a zip, i think that we must separate the onReceiveValue event
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

Segator

  • Jr. Member
  • **
  • Posts: 98
    • https://github.com/Nenirey
Re: LAMW how to get html content from a webview component
« Reply #5 on: August 16, 2020, 08:20:11 pm »
I make some progress, some import java stuff is missing and other changes, now webview has the onReceiveValue event and the EvaluateJavascript method, the application build fine and run but when i call the EvaluateJavascript method it crash, i attached the changes.
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

Segator

  • Jr. Member
  • **
  • Posts: 98
    • https://github.com/Nenirey
Re: LAMW how to get html content from a webview component
« Reply #6 on: August 16, 2020, 08:43:15 pm »
and this is my project example for test it, what i doing wrong?
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

jmpessoa

  • Hero Member
  • *****
  • Posts: 1623
Re: LAMW how to get html content from a webview component
« Reply #7 on: August 17, 2020, 05:50:19 am »

Congratulations!!!!

Done!

Improved jWebView!

New  Method "CallEvaluateJavascript"
New   property/event     "OnEvaluateJavascriptResult"
New demo "AppWebviewDemoEvaluateJavaScript"


Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Segator

  • Jr. Member
  • **
  • Posts: 98
    • https://github.com/Nenirey
Re: LAMW how to get html content from a webview component
« Reply #8 on: August 17, 2020, 02:02:26 pm »
Thanks to you jmpessoa, i learn viewing the changes in the code  ;)
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

jmpessoa

  • Hero Member
  • *****
  • Posts: 1623
Re: LAMW how to get html content from a webview component
« Reply #9 on: August 17, 2020, 09:25:31 pm »

Yes!

And the LAMW can  generate the interface code for the  'native" event, too!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Guser979

  • New Member
  • *
  • Posts: 21
Re: LAMW how to get html content from a webview component [SOLVED]
« Reply #10 on: September 13, 2020, 11:49:46 am »
I need to register my thanks here. This was very useful. Each day Lamw surprises me positively. Thanks Segator and JM. So far there has been no need to replace Lamw with Android Studio. I use Android Studio only for study and testing because I want to learn more about Java.

jmpessoa

  • Hero Member
  • *****
  • Posts: 1623
Re: LAMW how to get html content from a webview component [SOLVED]
« Reply #11 on: September 13, 2020, 08:37:14 pm »
Quote
I use Android Studio only for study and testing because I want to learn more about Java.

the doc is here:   [maybe you will need gradle 5.4.1 or +]

https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/docs/How_to_open_LAMW_project_with_AndroidStudio.txt

Remember that AS don't like anymore this line [like] in Manifest:

Quote
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28"/>

So you will need drop this line!

[and LAMW will reintroduce it when you reopen the project in another time...]

PS.  In practice when I need improve/fix or create a new component I open my demo project in AS to edit/fix the
java  side...
« Last Edit: September 13, 2020, 10:38:13 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Guser979

  • New Member
  • *
  • Posts: 21
Re: LAMW how to get html content from a webview component [SOLVED]
« Reply #12 on: September 13, 2020, 10:27:05 pm »
I want to learn more about java precisely because of Lamw. In a few days using Lamw I was able to produce useful tools for work. I have little free time and Lamw was very productive. I believe that anyone who has had contact with pascal has no difficulty creating with Lamw. Thank you all.

 

TinyPortal © 2005-2018