tags:

views:

314

answers:

2

Hi,

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

A: 

See if this can help: install Apk via Intent. Not sure if this is the way to go though.

Samuh
have you used this before ? if so please specify what "package", "xxx"refer to in ?Uri installUri = Uri.fromParts("package", "xxx", null);
rantravee
+4  A: 
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)

CommonsWare
sometimes it works , sometimes it reports it could not find the AndroidManifest file and cancels the instalation
rantravee
That suggests that perhaps you are calling `startActivity()` before the downloaded APK is fully flushed to the flash or something. I would try implementing this one step at a time, starting with using `startActivity()` on an APK you manually put on the SD card (e.g., adb push, DDMS File Manager, mount/drag/unmount from your development machine). Once that is working the way you want, blend in the download mechanism.
CommonsWare
Indeed that's the case I'm talking about . However I observed that if the apk is in the sdcard/download it is installed , but if put in the sdcard if will generate this error04-15 16:51:02.686: ERROR/filemap(215): mmap(0,0) failed: Invalid argument04-15 16:51:02.686: WARN/zipro(215): Unable to map '/sdcard/myapk.apk': Invalid argument04-15 16:51:02.695: DEBUG/asset(215): failed to open Zip archive '/sdcard/myapk.apk'04-15 16:51:02.695: DEBUG/filemap(215): munmap(0x0, 0) failedeven if the path is :INFO/mytag(196): instalation path is : ///sdcard/myapk.apk
rantravee