Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

android - Can We Install an APK From a ContentProvider?

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...