2

I'm trying to install apk programmatically by this code:

Intent intent = new Intent(Intent.ACTION_VIEW);
String mimetype = "application/vnd.android.package-archive";
intent.setDataAndType(Uri.fromFile(file), mimetype);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); 

And it works fine for all devices except Samsung Galaxy Tab GT-P1000.

On Galaxy Tab package manager starts installation but never ending it. There is a progress bar endless showing. After closing pakage manager by back key, I make certain that never the less apk has been installed to the system.

If I try to install the same apk just by startting it in file manager all goes correctly. Apk installs and package manager installation progress finishes in few seconds.

So, what can I do to make package manager work correctly when installing programmatically?

vok1980
  • 504
  • 5
  • 14
  • FYI, I frequently observe this on my Galaxy Tab, when my scripts install .apk files with the `am` command. Installation has always worked on the second try. – Julian Fondren Feb 09 '12 at 05:26

2 Answers2

0

To accomplish this you must include the apk's you wish to install to the device in the project that will install them. You can then use an intent to start installations.

Check this out - http://www.androidsnippets.com/install-an-apk-via-intent

Another way would be to create an ACTION_VIEW intent and use the setDataAndType method of the intent. Then use the context's method of startActivityForResult() to install the APK's.

You may also need the user-permission of INSTALL_PACKAGES in the manifest.

jjNford
  • 5,170
  • 7
  • 40
  • 64
  • I can't include this apk in the project. I'm downloading it form outside. And why do you think it can help? And of course I'm using in manifest. – vok1980 Mar 05 '12 at 10:16
0

The problem was in Galaxy Tab task manager specific. Due to bug in my app it was using 100% CPU. And it seems that task manager simply failed to switch on package manager. After I fixed a bug with 100% cpu, Package Manager begins working correctly.

vok1980
  • 504
  • 5
  • 14