local textfield = TextField.new(nil, "Downloading...") textfield:setX(10) textfield:setY(100) textfield:setScale(10)
stage:addChild(textfield)
local function onComplete(event) local out = io.open("|D|test.apk", "wb") out:write(event.data) out:close() end
local function onError() print("error") end
local function onProgress(event) print("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal) if event.bytesLoaded==event.bytesTotal then textfield:setText("Download Complete"); io.read("|D|test.apk") end end
Note that for this to work you can't use |D| nor |T|, since those aren't accessible to other android apps. You will need to request permission to write external storage and select a suitable folder.
Comments
https://stackoverflow.com/questions/15619693/silent-install-apk-programmatically-by-system-app-without-root
https://stackoverflow.com/questions/5803999/install-apps-silently-with-granted-install-packages-permission/5805299
My code:
Actually, I am unsure where the downloaded file is being saved.
[Edit]: I searched my phone but could not find the downloaded test.apk file.