下载并安装由内部存储器中的应用(APK) - 没有SD卡 [英] Download and install an application (apk) from internal memory - no SD card
问题描述
问候和新年快乐我的所有同事的程序员。
Greetings and a happy new year to all my fellow programmers.
我的code下载从远程服务器上的apk文件。我需要启动到code中的安装过程,而无需显式地安装它的用户。美中不足的是,我不能使用SD卡下载apk文件。
My code downloads an apk file from a remote server. I need to initiate the installation procedure through code, without user having to explicitly install it. The catch is that i cannot use an SD card download the apk file.
我可以导航到数据/数据/文件夹,可以看到我的文件下载。唯一的问题是,我不能把它安装。这就是我得到
I can navigate to the data/data/files folder and can see my file downloaded. The only problem is that i cannot get it installed. This is what i get
'/data/data/org.obs.testinstall.main/files/app.apk': Permission denied
据我所知,Android不给权限访问数据目录。 我的问题是我如何可以下载并无需使用SD卡安装应用程序(APK)。本申请并不意在发表在市场。我曾经同时使用内部存储使用尝试
I understand that Android does not give permission to access the data directory. My question is how can i download and install an application(apk) without using a SD card. This application is not intended to be published in the market. I have tried using both the Internal Storage using
FileOutputStream fos = openFileOutput("app.apk", Context.MODE_PRIVATE);
和缓存目录
File file = getCacheDir();
File outputFile = new File(file, "app.apk");
均可以得到相同的结果。权限被拒绝
Both give the same result .. "Permission denied"
当我改变code纳入SD卡的应用程序完美的作品,但使用的是SD卡是不是一种选择。
When i change the code to incorporate an SD card the application works perfectly, but using an SD card is not an option.
当然必须有办法做到这一点。这是很难相信,这样的障碍存在于Android的O / S。
Surely there must be a way to do this. It is hard to believe that such a handicap exist in the Android O/S.
有没有人这样做呢?任何解决办法?任何指针将是有益的。
Has anybody done this? Any workarounds? Any pointers would be helpful.
推荐答案
据其造成的Android应用程序无法读取 如果使用专用模式编写了另一个应用程序文件。
It it caused by android application can not read from another application file if it is written using PRIVATE mode.
您可以这样做:
String fileName = "tmp.apk";
FileOutputStream fos = openFileOutput(fileName,
MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
// write the .apk content here ... flush() and close()
// Now start the standard instalation window
File fileLocation = new File(context.getFilesDir(), fileName);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(fileLocation),
"application/vnd.android.package-archive");
context.startActivity(intent);
不过要小心,因为该文件现在是世界上可见, 并且可以通过在相同的设备中的任何应用中可以看出, 如果他们知道该文件的位置。
Be careful though, because that file is now world-visible, and can be seen by any application in the same device, if they know the file location.
这篇关于下载并安装由内部存储器中的应用(APK) - 没有SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!