Install data files from apk

Post Reply
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Install data files from apk

Post 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.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Install data files from apk

Post 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 :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Install data files from apk

Post by Antonio Linares »

I just tested this code from FiveTouch:

Code: Select all

#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Install data files from apk

Post by Antonio Linares »

Pritpal has published some code to do it:

https://groups.google.com/forum/#!topic ... E60mMvHXdc
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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Re: Install data files from apk

Post by Gale FORd »

I saw that. I will be working on it this weekend.
Thanks.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Install data files from apk

Post by Antonio Linares »

Gale,

Very good,

I look forward to know your results, thanks!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Install data files from apk

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply