Download and install

Vinians2006

Active Member
Licensed User
Longtime User
I want to create a button on my app where the user click and the app download the apk and tell the android to install it. How can I do it ?
I know how to download but how can I tell the android to install it with my own app being running ?
 

NJDude

Expert
Licensed User
Longtime User
After downloading the file you could install it like this:
B4X:
Dim iIntent As Intent 

iIntent.Initialize(iIntent.ACTION_VIEW, "file:///sdcard/MyAPK.apk")
iIntent.SetType("application/vnd.android.package-archive")

StartActivity(iIntent)
 
Upvote 0

Vinians2006

Active Member
Licensed User
Longtime User
Nice! But the download method on FTP dont require a URI, how can I convert an absolute FTP local path to a URI ? Im download things on the path File.DirInternal how can I access File.DirInternal using a URI format ?
See the download code:
B4X:
mFTP.DownloadFile("App.apk", _
         True, _
         File.DirInternal, _
         "App.apk")
Thanks
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You just need the location of the downloaded file:
B4X:
TheFile = File.DirInternal & "/MyApk.apk"

iIntent.Initialize(iIntent.ACTION_VIEW, "file:///" & TheFile)

...

You download first, finished downloading, then install.
 
Last edited:
Upvote 0

Vinians2006

Active Member
Licensed User
Longtime User
Ok, I downloaded the file and verified that the file was there. But Im getting this BIG error see:
main_ftp_downloadcompleted (java line: 329)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/data/data/com.netsoft.nsmobile/files/NSMobile.apk typ=application/vnd.android.package-archive flg=0x20000 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
at android.app.Activity.startActivityForResult(Activity.java:2836)
at android.app.Activity.startActivity(Activity.java:2942)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:665)
at com.netsoft.nsmobile.main._ftp_downloadcompleted(main.java:329)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at anywheresoftware.b4a.BA$1.run(BA.java:218)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/data/data/com.netsoft.nsmobile/files/NSMobile.apk typ=application/vnd.android.package-archive flg=0x20000 }
Installing file.
PackageAdded: package:com.netsoft.nsmobile
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Oh my gosh..... Im sorry for a lot of question but I really need this. My app is done and I need this working.
Thanks a lot for trying to help me.
 
Upvote 0

Vinians2006

Active Member
Licensed User
Longtime User
Thanks a lot. Its seems that worked 50%, now Im getting this message "Há um problema com a anaslise do pacote" in english "There's a problem analising the package". Its because its a not signed apk ?
 
Upvote 0
Top