Programming on Harbour for Android
I present here one small simple Android application which, however, can be helpful:Download h4aFirstApp_v6.zip - sources.
Download h4aFirstApp.apk - ready for installing to Android device.
It is a demo program, but you can create on its basis something useful for yourself. For this we need to rewrite to fit your needs the \h4aFirstApp\source\testhrb.prg ( a source file, written with Harbour ) and rebuild a package h4aFirstApp.apk, using the \h4aFirstApp\build.bat (Windows) or \h4aFirstApp\build.sh (Linux).
But before you need to download and install Java Development Kit - JDK ( don't confuse with JRE - Java Runtime ) and Android SDK Tools. You may install the full Android Studio, but it is not necessary. After installing the Android SDK Tools you need to run SDK Manager и install additionally some components.
Then you will need to edit the \h4aFirstApp\h4a\setenv.bat - register there your paths to the installed products.
Testhrb.prg must contain at least two functions:
- FModList() - returns a string that is displayed on the main screen as a menu. Menu items must be framed on both sides with **
- FModExec( iMod ) - implements menu items, should return a string that is displayed on the screen of the application.
- h4a_HomeDir() - returns the application home directory
- h4a_CalcExp( cExp ) - returns the result of executing of the cExp, which may include any Harbour functions and operators
- h4a_LS( cDir ) - returns a string - list of files in cDir
- h4a_isInternetOn() - checks the Internet connection
- h4a_wrlog( cString ) - writes to a system journal ( it may be read then, if the program is executed on emulator )
- h4a_webload( cHtmlPage ) - loads a new web page to the already created WebView
- h4a_getsysdir( cType ) - returns public directory of a certain type ( "ext" - base directory External Storage, "doc" - Documents, "pic" - Pictures, "mus" - Music, "mov" - Movies, "down" - Downloads, "ring" - Ringtones )
Even such a simple structure allows to implement useful features - for example, a set of reports on the current status (info about the shipment of goods, the state of bank accounts, balances in warehouses, etc.).
One of menu items may implement the program update - and copy a new testhrb.hrb from some server for using instead of that one, which is in apk - this is alreay implemented here since the Version 2, this is the way as the Update program works.
Since the version 5 it is possible to call Harbour functions from the Javascript in WebView, to create a multiline prg strings and send them from WebView
to Harbour VM for execution. It is a way to creating web-interface, based on Javascript + Harbour interaction.
- Version 6: h4a_webload( cHtmlPage ) and h4a_getsysdir( cType ) Harbour functions added.
- Version 5: Now application behaves normally when device orientation is changed. Simple menu introduced. Added a prototype of a JavaScript -> Java -> Harbour bridge.
- Version 4: Mastering the technique of calling Java methods from Harbour and debugging techniques - added Harbour function h4a_isInternetOn() to determine whether there is an Internet connection and h4a_Wrlog( sText ) - write debug messages to a log for saving to a file using adb shell logcat. Scripts are slightly modified.
- Version 3a: Scripts for building package under Linux added, fixed a bit scripts for Windows.
- Version 3: Now, if the string, returned by FModExec(), begins with <html, it is opened not in a TextView, but in WebView widget, i.e. it is possible to use any kind of html formatting, including using of css and javascript. The title of a module is set now to appropriate menu item. The standard icon is changed to Harbour logo.
- Version 2: Added additional support for hrb updates. An update module is included in testhrb.prg, it allows to get new hrb files from this site. Besides, a problem solved, related to some Android feature - it doesn't close an application after closing a main window (Activity).
And yet another links. Projects on the Github: h4aFirstApp и set of scripts to create libharbour.so for Android. And this is a little tutorial about h4aFirstApp setup from Roberto Lopez.
Tweet
Your name:
Email address:
(not be shown publicly)
  |