Page 1 of 1
How to access apk extension files
Posted: Tue Nov 18, 2014 4:04 am
by meixingm
When I saved my .apk it was large because of some videos. I'd like to save the videos in an .apk extension file and access them from my app. Would it be exactly the same as if the videos were saved with the application?
on openCard
mobileControlSet "videoControl", "filename", specialFolderPath("engine") & "/video clips/baba.mp4"
mobileControlDo "videoControl", "play"
end openCard
Would that be the location of the video on the phone?
Also if i save the file to a zip is there anything I need to do with the licensing key?
Any help would be appreciated! thanks!
Re: How to access apk extension files
Posted: Thu Nov 20, 2014 12:11 pm
by rmuzzini
apparently it's not as simple as it seems.
see
http://developer.android.com/google/pla ... files.html
The specific location for your expansion files is:
<shared-storage>/Android/obb/<package-name>/
<shared-storage> is the path to the shared storage space, available from getExternalStorageDirectory()
not sure how to reach it in LC (no specialFolderPath key found about in the dictionary)
and
To ensure proper behavior, you must not delete, move, or rename the expansion files
plus
However, if possible, it's best if you use an expansion file format that allows you to read directly from the file instead of requiring you to unpack the data
therefore, you have to force users to keep both the expansion zipped files and your unzipped asset folder.
even if , about specialFolderPath, the dictionary says
Android Note: An Android application is installed on the phone in the form of its zip package. This means that any assets that are included are not available as discrete files in the native filesystem. In order to manage this the engine essentially 'virtualizes' the asset files you include, allowing (read-only) manipulation with all the standard LiveCode file and folder handling syntax. To access the assets you have included within your application, use filenames relative to specialFolderPath ("engine").
maybe a new key like
specialFolderPath("espansionfiles")
would be appreciated…
personally, in the past, i resolved this google limitation by forcing my app at the very first launch to download a .zip files from my server, unzipping it in the "documents" folder and finally deleting it.
but any other solution by any experts here would be appreciated too, for sure…
regards.
Re: How to access apk extension files
Posted: Mon Dec 01, 2014 9:27 am
by meixingm
do you think you could post your code to show me how you did that? it'd be alot of help

Re: How to access apk extension files
Posted: Mon Dec 01, 2014 5:12 pm
by MaxV
I think
rmuzzini had in mind this:
Code: Select all
on PreOpenStack
if "myvideo.mp4" is not among the lines of the files then
put URL "www.mysite.com/myvideo.mp4" into URL "file:myvideo.mp4"
end if
end PreOpenStack
Re: How to access apk extension files
Posted: Mon Dec 15, 2014 6:38 pm
by rmuzzini
no, actually i was speaking about a real installer.

usually my apps have to be used even off line, therefore media files must be local.
:-/
here's a sample code. not clean, poor commented, but it works. if need more explanation, feel free to ask.
Code: Select all
[stack script]
global gPrefPath
constant kPreFold = "myAppPrefFodler"
on openStack
//…
put specialFolderPath("Documents") & SLASH & kPreFold into gPrefPath
//…
end openbStack
[card script]
global gPrefPath, gMediaPath
local sDownloadInProgress, sMediaDestination
constant kRepository = "http://www.example.com/_app/MEDIA.zip"
on mouseUp //enter button
if sDownloadInProgress then exit mouseUp
// …
if there is not a folder (gPrefPath & SLASH & "MEDIA") then
doDownload
else
put gPrefPath & SLASH & "MEDIA" & SLASH into gMediaPath //pretty useless to use this global, actually… lazy one…
visual effect push left
go to cd "home"
end if
end if
end mouseUp
command doDownload
put "Please, wait…" into fld "status"
show fld "status" //a feeback to user
show img "progress" //if you wish
put gPrefPath & SLASH & "media.zip" into sMediaDestination
put true into sDownloadInProgress
put "Downloading media files. Please wait…" into fld "status"
libURLDownloadToFile kRepository,sMediaDestination #,"downloadComplete"
end doDownload
on downloadComplete
put "" into tResult
if there is not a file sMediaDestination then
put "I got en error while downloading the archive!" into tResult
else
put "Installing. Please wait…" into fld "status"
listZipContents sMediaDestination
put extractArchive(sMediaDestination,gPrefPath) into tResult
delete file sMediaDestination
end if
if there is not a folder (gPrefPath & SLASH & "MEDIA") then put cr & "Error on unzipping!" after tResult
if tResult is not "" then
put "Unexpected error:" & cr & tResult into fld "status"
hide img "progress"
exit downloadComplete //or: 'exit to top', it's up to you
end if
put "Done!" into fld "status"
hide fld "status"
hide img "progress"
delete local sDownloadInProgress
put gPrefPath & SLASH & "MEDIA" & SLASH into gPath //see prev comment about…
visual effect push left
go to cd "home" //choose your destination…
end downloadComplete
#here below some very old, dear, public runrev scripts
command listZipContents pArchive
revZipOpenArchive pArchive, "read"
put revZipEnumerateItems(pArchive) into tZipContents
put tZipContents into field "FileList" //don't forget to create an invisible fld "FileList" on the purpose. or use a local var or a card prop etc., if you prefer
revZipCloseArchive pArchive
end listZipContents
function extractArchive pArchive, pWhere
local sZipCancelled //usefull to manage things if the user close the stack before having completed the installation
put false into sZipCancelled
put "" into tResult
put "" into tFolderName
local sLocation
put pWhere into sLocation
#open the archive
revZipOpenArchive pArchive, "read"
set the itemDel to "/"
put item 1 of line 1 of field "FileList" into tFolderName
set the itemDel to ","
put the number of lines of field "FileList" into tTotal
put 0 into tCurrent
repeat for each line tItem in field "FileList"
add 1 to tCurrent
put "Installing:" && tCurrent && "of" && tTotal into line 2 of fld "status"
if char 1 of tItem = "." OR char 1 of tItem = "_" then next repeat //avoid to extract osx garbage. if you use a var, then 'filter myVar without' etc.
if char -1 of tItem is "/" then
#it's a folder. ignore it, as ziplib does not manage folders
else if item 6 of revZipDescribeItem(pArchive,tItem) is "deflate" then
#BUT be sure the foder exists!
set the itemDel to "/"
ensureFolder sLocation & "/" & item 1 to -2 of tItem
set the itemDel to ","
revZipExtractItemToFile pArchive, tItem, sLocation & "/" & tItem
else
#what the heck?! it's not a folder, but the compression method is unknown!
#insert some error management, just in case
put "The archive seems to be corrupted to me!" into tResult
exit repeat
end if
end repeat
revZipCloseArchive pArchive
return tResult
end extractArchive
command ensureFolder pFolder
if there is a folder pFolder or pFolder is empty then
exit ensureFolder
end if
set the itemDel to "/"
ensureFolder item 1 to -2 of pFolder
create folder pFolder
end ensureFolder