可我们安装的APK从ContentProvider的? [英] Can We Install an APK From a ContentProvider?
问题描述
我的工作库,允许应用程序进行自我更新,对于那些正在外面分布式Android Market的。
I am working on a library to allow apps to self-update, for those that are being distributed outside of the Android Market.
我原来的计划是包括code,它会下载apk文件到内部存储器,然后通过的ContentProvider
和<$ C从那里安装$ C>内容:// 乌里
。然而,当我试过了,安装系统甩了跳过目录:警示LogCat中,并没有实际安装它。有一次,我切换到下载APK到外部存储,并使用文件://
乌里
与 ACTION_VIEW
安装意图
,它的工作。
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.
在跳过目录的消息似乎是由 parsePackage()
在 PackageParser
登录,这似乎假定它正在与一个文件
。这将表明,我们不能使用内容://
乌里
值
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.
有没有人成功地使用 ACTION_VIEW
在应用程序/ vnd.android.package存档
意图
与内容://
乌里
?如果是这样,在那里设立一些具体的伎俩的ContentProvider
,使得它的工作?
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?
谢谢!
推荐答案
我会认为这是不可能的,作为Java API似乎并没有答应。的ContentProvider的中openFile()
返回 ParcelFileDescriptor
,你可以从中获得 java.io。的FileDescriptor
。然后,您可以使用此的FileDescriptor
来打开任何一个的FileInputStream
或的FileOutputStream
。不幸的是,你不能用它来打开一个的RandomAccessFile
(尽管的RandomAccessFile
适用于描述一样的为别人,你需要构造距离API丢失)。
I would assume this is not possible, as the Java API doesn't seem to allow it. ContentProvider's openFile()
returns a ParcelFileDescriptor
, from which you can obtain a java.io.FileDescriptor
. You can then use this FileDescriptor
to open either a FileInputStream
or a FileOutputStream
. Unfortunately, you can't use it to open a RandomAccessFile
(despite the fact that RandomAccessFile
works on descriptors just the same as the others, the constructor you'd need is just missing from the API).
由于APK文件是ZIP文件,必须读出顺序(你必须寻求最终找到文件目录),我想安装的实施将需要一个的RandomAccessFile
,所以它不会有可能支持你想实现的情况。
As APK files are ZIP files, which must be read out of order (you have to seek to the end to find the file directory), I assume the implementation of installation will require a RandomAccessFile
, so it would not have been possible to support the case you're trying to implement.
这篇关于可我们安装的APK从ContentProvider的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!