Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automatic install of apk

Tags:

android

I'd like to know if it is possible to trigger programmatically the installation of an apk that is on the card ?

like image 698
rantravee Avatar asked Apr 14 '10 14:04

rantravee


2 Answers

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);

(courtesy of anddev.org)

like image 183
CommonsWare Avatar answered Oct 05 '22 22:10

CommonsWare


Just in case somebody is looking for this info.... If you want to install an apk which you also programmatically downloaded and stored in your private "files" folder (ie. "/data/data/com.yourapp.name/files"), you need to get the uri for the full path by first using getFileStreamPath as follows:

File fullPath = getFileStreamPath("name_of_downloaded_app.apk");

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(fullPath), "application/vnd.android.package-archive");
startActivity(intent);

Hope this helps...

like image 44
hopia Avatar answered Oct 06 '22 00:10

hopia