Install data files from apk

Install data files from apk

Postby Gale FORd » Thu Jul 09, 2015 3:17 pm

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.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Install data files from apk

Postby Antonio Linares » Thu Jul 09, 2015 8:31 pm

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: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Install data files from apk

Postby Antonio Linares » Thu Jul 09, 2015 8:48 pm

I just tested this code from FiveTouch:

Code: Select all  Expand view  RUN
#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: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Install data files from apk

Postby Antonio Linares » Thu Jul 09, 2015 8:55 pm

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

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

Re: Install data files from apk

Postby Gale FORd » Thu Jul 09, 2015 9:28 pm

I saw that. I will be working on it this weekend.
Thanks.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Install data files from apk

Postby Antonio Linares » Fri Jul 10, 2015 11:23 am

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: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Install data files from apk

Postby Antonio Linares » Mon Apr 02, 2018 1:36 am

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


Return to FiveTouch

Who is online

Users browsing this forum: No registered users and 4 guests