Lazarus

Programming => Operating Systems => Android => Topic started by: tintinux on April 14, 2016, 08:28:50 am

Title: [SOLVED] Http requests with Android
Post by: tintinux on April 14, 2016, 08:28:50 am
Hi

With Synapse I can perform Http Get request on Windows, Linux and OS/X.

On Android it compiles but when a get request is done the application ends  without message.
Of course, I have enabled Internet access in the manifest.
I'm using LazToApk targetting an Android 4 system (not working with Android >= 5)
I do not find anything in the log, but maybe I have not the tool for that (can't connect with adb on this phone)

Was anyone successful in this area, with Synapse or another library ?

Thanks for hints.

 
Title: Re: Http requests with Android
Post by: hnb on April 14, 2016, 09:20:59 am
Try to use mORMot. Works for me very well on Android.
Title: Re: Http requests with Android
Post by: tintinux on April 14, 2016, 11:28:49 am
OK, thanks, I will try, but :

1) is it really free software ?
2) does it now works on Linux 64 bits  ?

Regards

Title: Re: Http requests with Android
Post by: BeniBela on April 14, 2016, 02:45:06 pm
Android has its own Java http libraries

You can call those with JNI.

I wrote a wrapper to call the HttpComponent library. Sadly, they were deprecated in Android 22 and seemingly removed in Android 23.
Title: Re: Http requests with Android
Post by: hnb on April 15, 2016, 02:41:24 pm
1) is it really free software ?
2) does it now works on Linux 64 bits  ?

1) yes very liberal licence.
2) AFAIK 32 bits Linux, but that part maybe will work for 64 bits
Title: Re: Http requests with Android
Post by: tintinux on April 15, 2016, 07:54:30 pm
Quote from: Benibela
I wrote a wrapper...

I suppose it is internettools...  which looks a simple and efficient library (just the opposite of mORMot).

Is there any hope you will search why it is deprecated on the recent Android SDK, and make it working ?

I only need httpRequest from internetaccess.pas and even not https.

This would be great !

Regards


Title: Re: Http requests with Android
Post by: BeniBela on April 15, 2016, 11:42:28 pm

I suppose it is internettools...  which looks a simple and efficient library (just the opposite of mORMot).

It is probably rather inefficient, when it calls Java functions for everything

Is there any hope you will search why it is deprecated on the recent Android SDK, and make it working ?

Google put an unreleased alpha  version of the HttpComponents in the early Android  and then they could not update it for backward compatibility, so it was just sitting there as legacy lib. And they say the HttpURLConnection is more efficient nowadays.


It seems they only removed it from the SDK, so it still works on the devices. You just cannot compile java sources that uses it and it is undocumented. But who knows how long.


androidinternetaccess.pas is the file containing the wrapper
Title: Re: Http requests with Android
Post by: Leledumbo on April 16, 2016, 09:34:21 am
With Synapse I can perform Http Get request on Windows, Linux and OS/X.

On Android it compiles but when a get request is done the application ends  without message.
Of course, I have enabled Internet access in the manifest.
...
Was anyone successful in this area, with Synapse or another library ?
Works fine on my phone. One of the LazAndroidModuleWizard demos (the GUI one) also does HTTP request, which also works fine, requesting the same http://www.freepascal.org as in my screenshot.
I do not find anything in the log, but maybe I have not the tool for that (can't connect with adb on this phone)
logcat can be run on the device itself and there's an app in the play store wrapping that.
Title: Re: Http requests with Android
Post by: tintinux on April 20, 2016, 12:10:41 pm
Hi

Quote from: leledumbo
One of the LazAndroidModuleWizard demos (the GUI one) also does HTTP request
Could you say which one more precisely or where it can be found ?
The "GUI" source I find in demo folder (AppAntDemo1) is displaying 2 buttons, a timer and "Lazarus Rocks", and I do not see any Http Request.
The only other is "NOGUI".

Quote from: leledumbo
logcat can be run on the device itself and there's an app in the play store wrapping that
Yes, thanks. However it seems necessary to be root, and I have not found how root to with adb not working...
Maybe I will try to find another more standard phone, because the one I have require specific adb drivers not working.

Regards
Title: Re: Http requests with Android
Post by: Handoko on April 20, 2016, 04:23:22 pm
Could you say which one more precisely or where it can be found ?

Here:
[your_lazandroidmodulewizard_folder]/trunk/demos/Eclipse/AppDemo1
Title: Re: Http requests with Android
Post by: jmpessoa on April 20, 2016, 06:00:09 pm
Yes, and more:

"lazandroidmodulewizard"\demos\Eclipse\AppHttpClientDemo1
"lazandroidmodulewizard"\demos\Eclipse\AppHttpClientDemo2
"lazandroidmodulewizard"\demos\Eclipse\AppHttpClientCookiesDemo1

NOTE: All LAMW/eclipse project are "Ant"  compatibles!

Please, see "readme.txt" how to use demos:

To use/test any demo App you will need:

1. Open the project ...  "...\jni"

. Upgrade your project [or demo] code templates:
    Lazarus IDE --> menu Tools --> [Lamw] Android Module Wizard --> Upgrade code Templates [*.lpr, *.java]

2. configure "build.xml"  to match your system... and "AndroidManifest.xml":       
"android:targetSdkVersion"   to match "build.xml"

3. configure the ".lpi" to match your system...

NOTE 1: if you need configure for "x86" please, go to folder "...\jni\build-modes"  and see "readme.txt" to replace some lines in ".lpi"

NOTE 2. The LAMW produce many ".bat" or ".sh" to logcat ... there are more in  "...\utils", too

4. Lazarus IDE --> Run --> "build"   [to produce the pascal jni ".so"]

5. Connect your Device-PC  via usb ...

6. Lazarus IDE --> Run --> "[Lamw] Build Android Apk and Run"

Thanks to All!
Title: Re: Http requests with Android
Post by: tintinux on May 02, 2016, 09:39:03 am
Ok, the jHttpClient installed with LAMW works fine for me !
Title: Re: Http requests with Android
Post by: JD on May 02, 2016, 11:08:02 am
Try to use mORMot. Works for me very well on Android.

What version of FPC are you using with it? I've been unable to compile the mORMot example because of a compiler error with FPC 3.0

JD
Title: Re: [SOLVED] Http requests with Android
Post by: DonAlfredo on May 02, 2016, 12:06:25 pm
For the mORMot, I always use trunk.
With the RTTI patch for more convenience (on i386 and x86_64):
https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/blob/master/patchfpc/fpctrunkrtti.patch

(I am busy at the moment to get the method invoke working for ARM !)
Title: Re: [SOLVED] Http requests with Android
Post by: tintinux on May 02, 2016, 12:31:31 pm
Hi

I use currently FPC3.1.1 as specified in this page (http://wiki.freepascal.org/LAMW)

But I have not used mORMot because it is mixing Http and SqlLite in a strange way, and I do not need SqlLite at all.

So, I only use the jHttpClient installed with LAMW, and it works fine.

Hope this helps.

Title: Re: [SOLVED] Http requests with Android
Post by: Thaddy on May 02, 2016, 12:37:40 pm

But I have not used mORMot because it is mixing Http and SqlLite in a strange way, and I do not need SqlLite at all.
Then that's a bug in mORMot. Report it. It usually gets fixed pretty quick. There should never be a dependency on sqlite like that.
Title: Re: [SOLVED] Http requests with Android
Post by: DonAlfredo on May 02, 2016, 03:09:52 pm
SQLite3 is not needed for a plain http server by mORMot.
See Sample 9 in the Samples directory.
Title: Re: [SOLVED] Http requests with Android
Post by: BeniBela on May 02, 2016, 03:25:38 pm
Perhaps it is an issue with Lazarus' packages, because they always compile all units, not just those used?
TinyPortal © 2005-2018