Page 1 of 1

Install data files from apk

PostPosted: Thu Jul 09, 2015 3:17 pm
by Gale FORd
After quite a bit of searching it seems there is no easy way to install data that have been included in apk.
It is recommended to use assets in apk and then the installed program would use java functions getAssets().open("path/file.ext") or getResources() to access the data stream in apk
I can't find getAssets() or getResources() in Harbour or QT.
I would rather not have to download separate Data, PRG, and other files during installation.

Re: Install data files from apk

PostPosted: Thu Jul 09, 2015 8:31 pm
by Antonio Linares
Gale,

I have just emailed Priptpal Bedi (HbQT developer) to know if GetAssets() is supported in HbQT.

I just realized that an APK is a ZIP file, so if we could get the path of the APK then we could extract the
files from the APK itself using Harbour :-)

Re: Install data files from apk

PostPosted: Thu Jul 09, 2015 8:48 pm
by Antonio Linares
I just tested this code from FiveTouch:

Code: Select all  Expand view
#include "FiveTouch.ch"
     
function Main()
     
   local n

   for n = 1 to 20
      MsgInfo( QStandardPaths():StandardLocations( n ):Value( 0 ) )
   next

return nil      


But not sure if one of the returned values is the one that we are looking for

Re: Install data files from apk

PostPosted: Thu Jul 09, 2015 8:55 pm
by Antonio Linares
Pritpal has published some code to do it:

https://groups.google.com/forum/#!topic/qtcontribs/AE60mMvHXdc

FUNCTION __testRDD()
LOCAL dir_, cQrcFile, cPath

cPath := QStandardPaths():writableLocation( 9 ) // 9 == the only one which works, tested with 1.2.3 etc.

ft_mkDir( cPath + "/" + "accmix" ) // it will fail if "accmix" already exists

IF ! hb_fileExists( cPath + "/" + "accmix" + "/" + "ACCFBASE.MXD" )
cQrcFile := hb_base64Decode( __hbqtLoadResource( ":/tables/ACCFBASE.MXD" ) )
hb_MemoWrit( cPath + "/" + "accmix/ACCFBASE.MXD", x )
ENDIF
USE ( cPath + "/" + "accmix/ACCFBASE.MXD" ) VIA "DBFCDX"
dbGoTop()
hbqt_debug( FieldGet( 1 ) )
USE
dir_:= Directory( cPath + "/" + "accmix/*.*" )
hbqt_debug( cPath + "/" + "accmix/*.*" )
AEval( dir_, {|e_| hbqt_debug( hb_ValToExp( e_ ) + Chr( 10 ) ) } )

RETURN NIL



In the .qrc
========
<file>tables/ACCFBASE.MXD<file>

The binaries must be stored in .qrc hb_base64Encode()ed.


As Android is a Linux kernel, make sure that file/folder names are case-sensitive.

QStandardPaths():writableLocation( 9 ) gives a permanent place to
read/write whatever you want. So create a unique folder inside there
and organize the files in subfolders. This will also ensure that whenever
you ship another version of your app, the data is not lost.

Re: Install data files from apk

PostPosted: Thu Jul 09, 2015 9:28 pm
by Gale FORd
I saw that. I will be working on it this weekend.
Thanks.

Re: Install data files from apk

PostPosted: Fri Jul 10, 2015 11:23 am
by Antonio Linares
Gale,

Very good,

I look forward to know your results, thanks!

Re: Install data files from apk

PostPosted: Mon Apr 02, 2018 1:36 am
by Antonio Linares
In QT Creator project file:

COMMON_DATA.path = /assets
COMMON_DATA.files = $$PWD/FiveTouch.ch
COMMON_DATA.files += c:/harbour/include/hbclass.ch
COMMON_DATA.depends = FORCE
INSTALLS += COMMON_DATA

From our source:

QFile( "assets:/FiveTouch.ch" ):copy( "FiveTouch.ch" )
MsgInfo( File( "FiveTouch.ch" ) ) // shows .T.