问题描述
我已经存储在的apk文件的另一个应用程序在我的/ RES / raw目录,并希望给用户一个提示进行安装。这是我目前的code:
I have stored a .apk file for another app in my /res/raw directory and wish to give the user a prompt to install it. Here's my current code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("android.resource://" + getPackageName() + "/res/raw/myapk.apk")), "application/vnd.android.package-archive");
startActivity(intent);
然而,当意图运行,我得到一个解析错误:有一个问题解析包
该.apk文件文件是当我运行其他应用程序通过月食在/ bin目录下创建的。
The .apk file is the one created by eclipse in the /bin directory when I run the other application.
我将如何完成这一正确纲领性本地安装?
How would I accomplish this programmatic local install correctly?
推荐答案
我想它了。最后我把我的.apk文件中的/资产目录和编程复制它的地方,我从它安装在SD卡。这是我的code:
I figured it out. I ended up putting my .apk file in the /assets directory and copying it programatically to the sd card where I installed it from. Here's my code:
AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open("myapk.apk");
out = new FileOutputStream("/sdcard/myapk.apk");
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
in.close();
in = null;
out.flush();
out.close();
out = null;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/sdcard/myapk.apk")), "application/vnd.android.package-archive");
startActivity(intent);
}catch(Exception e){
// deal with copying problem
}
希望这将有助于其他人有类似的问题!
Hopefully this will help someone else with a similar question!
这篇关于编程方式安装在/ RES的.apk文件/生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!