Recent

Author Topic: [SOLVED] Http requests with Android  (Read 9284 times)

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
[SOLVED] Http requests with Android
« 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.

 
« Last Edit: May 02, 2016, 09:39:24 am by tintinux »
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: Http requests with Android
« Reply #1 on: April 14, 2016, 09:20:59 am »
Try to use mORMot. Works for me very well on Android.
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: Http requests with Android
« Reply #2 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

Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

BeniBela

  • Hero Member
  • *****
  • Posts: 908
    • homepage
Re: Http requests with Android
« Reply #3 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.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: Http requests with Android
« Reply #4 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
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: Http requests with Android
« Reply #5 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


Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

BeniBela

  • Hero Member
  • *****
  • Posts: 908
    • homepage
Re: Http requests with Android
« Reply #6 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

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Http requests with Android
« Reply #7 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.

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: Http requests with Android
« Reply #8 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
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Http requests with Android
« Reply #9 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

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: Http requests with Android
« Reply #10 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!
« Last Edit: April 20, 2016, 08:50:06 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: Http requests with Android
« Reply #11 on: May 02, 2016, 09:39:03 am »
Ok, the jHttpClient installed with LAMW works fine for me !
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: Http requests with Android
« Reply #12 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
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: [SOLVED] Http requests with Android
« Reply #13 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 !)

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: [SOLVED] Http requests with Android
« Reply #14 on: May 02, 2016, 12:31:31 pm »
Hi

I use currently FPC3.1.1 as specified in this page

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.

Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

 

TinyPortal © 2005-2018