Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can We Install an APK From a ContentProvider?

Tags:

android

I am working on a library to allow apps to self-update, for those that are being distributed outside of the Android Market.

My original plan was to include code that would download the APK file to internal storage, and then install it from there via a ContentProvider and a content:// Uri. However, when I tried that, the installer system dumped a "Skipping dir: " warning to LogCat and failed to actually install it. Once I switched to downloading the APK to external storage and using a file:// Uri with the ACTION_VIEW installer Intent, it worked.

The "Skipping dir:" message seems to be logged by parsePackage() in PackageParser, which seems to assume that it is working with a File. That would suggest that we cannot use content:// Uri values.

Has anyone successfully used ACTION_VIEW on a application/vnd.android.package-archive Intent with a content:// Uri? If so, was there some specific trick in setting up the ContentProvider that made it work?

Thanks!

like image 250
CommonsWare Avatar asked Mar 09 '12 16:03

CommonsWare


People also ask

What is the purpose of Contentprovider in Android?

A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.

Can you install APK without rooting?

You don't need ROOT permissions to get the list of Installed Apps. You can do it with android PackageManager.

Can I create an APK from an installed app?

There is no manual way on how to create an apk from an installed app on your Android smartphone. Hence you need to use a third-party application available on Google Play Store known as App Country Finder.

How do I import an APK file?

Just open your browser, find the APK file you want to download, and tap it – you should then be able to see it downloading on the top bar of your device. Once it's downloaded, open Downloads, tap on the APK file and tap Yes when prompted. The app will begin installing on your device.


1 Answers

The documentation for ACTION_INSTALL_PACKAGE is incorrect. It too will only accept files.

My only suggestion would therefore be to create a copy of the file in the applications file area, make it world readable, and clean up any left-over files at a later date.

Previous incorrect answer: In 4.0 and above there is a ACTION_INSTALL_PACKAGE which will accept a content:// URI (JavaDoc), but, prior to that, you're limited to installing via ACTION_VIEW which does assume the URI passed is a file:// URI.

like image 127
Al Sutton Avatar answered Oct 06 '22 00:10

Al Sutton