* * *

Author Topic: Android Module Wizard  (Read 292747 times)

lucabertoncini

  • New member
  • *
  • Posts: 7
Re: Android Module Wizard
« Reply #975 on: July 17, 2017, 01:40:17 pm »
Hi JMPessoa,
thanks for your time.
I took a look at the demos to try to understand how to use this interesting code.
If I’m right, to be able to post a JSON string with jHTTPClient I should write a procedure similar to jHTTPClient_AddValueForPost2 but with only a single parameter.


Something like

procedure jHTTPClient_AddStringForPost(env: PJNIEnv; _jHTTPClient: JObject; _AString: string);
  var
  jParams: array[0..0] of jValue;
  jMethod: jMethodID = nil;
  jCls: jClass = nil;
begin
  jParams[0].l := env^.NewStringUTF(env, PChar(_AString));
  jCls := env^.GetObjectClass(env, _jHTTPClient);
  jMethod := env^.GetMethodID(env, jCls, 'AddStringForPost', '(Ljava/lang/String;)V');
  env^.CallVoidMethodA(env, _jHTTPClient, jMethod, @jParams);
  env^.DeleteLocalRef(env, jParams[0].l);
  env^.DeleteLocalRef(env, jCls);
end;

What about an https connection? In Android I need to use a different object  HttpsURLConnection.
In this case I need to change the function jHttpClient_Post with this:
jMethod := env^.GetMethodID(env, jCls, 'Post', '(Ljava/net/HttpsURLConnection;)Ljava/lang/String;');

These are the two test I'll do in the next days. Do you think it is the right way?

lucabertoncini

  • New member
  • *
  • Posts: 7
Re: Android Module Wizard
« Reply #976 on: July 17, 2017, 05:00:27 pm »
I've found this tutorial.

http://www.pacifier.com/~mmead/jni/delphi/JEDI/DOCS/delphi-jni-1.html

Everything I wrote in the previous post was wrong!

I'll try the way of using fphttpclient and fpsock library.

Thank you!

jmpessoa

  • Hero Member
  • *****
  • Posts: 903
Re: Android Module Wizard
« Reply #977 on: July 17, 2017, 06:16:08 pm »

Quote
http://www.pacifier.com/~mmead/jni/delphi/JEDI/DOCS/delphi-jni-1.html

Yes, a great "core" tutorial....

But LAMW code architecture is much easier!

First we write a java class to wrapper some android API..
Example:  jHttpClient is a wrapper for android HttpsURLConnection...
See the demos "AppHttpClientDemo1" and AppHttpClientDemo2 .....AppHttpClientCookiesDemo1, etc...
You can see the java stuff in folder "YourProject/scr/........."

Note: To use fpc FCL core, you often need to copy the source code to you project
"jni"  folder ....
Example: To use  "fphttpclient" copy "fphttpclient.pp",  "httpdefs.pp" and "httpprotocol.pp" to you project "jni" folder

But, I think you can try first the LAMW jComponents!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

lucabertoncini

  • New member
  • *
  • Posts: 7
Re: Android Module Wizard
« Reply #978 on: July 17, 2017, 06:23:32 pm »
Ok, in the next days I'll go deeper. Thanks!

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus