使用1 APK安装多个Android应用 [英] Installing multiple android apps with 1 APK
问题描述
我有两个单独的应用程序.目前,我可以单独安装它们.我想了解如何使用单个APK安装它们.
I have two separate apps. Currently I am able to install them separately. I wanted to find out how I can install them using a single APK.
我希望能够使两个应用程序都彼此独立运行,但是我希望能够将它们打包在一起.
I want to be able to have both apps still run independently of each other but I wanted to be able to package them together.
这样,当用户转到Google Play商店时,他们看到了一个应用程序,但实际上安装了两个应用程序.
This way when a user goes to the google play store they see one app, but it actually install both the apps.
谢谢, 杰夫
推荐答案
您不能仅在不显示用户的情况下直接安装两个应用程序,您可以做的是创建一个新应用程序,您将在其中放置2个apk文件.在build文件夹内的"raw"文件夹中.并推动它们一起打开,这些应用将向用户显示一个对话框,询问权限,如果用户允许,则会安装.
You cannot just install two apps directly without showing the user, the thing that you can do is to create a new app in which you will put your 2 apk files in the "raw" folder inside build folder. And push them to open together, those app will show a dialog to user to ask about permissions and will be installed if user allows.
这是执行此操作的代码:
Here is the code to do that:
for (int a=0;a<names.length;a++)
{
InputStream in = null;
OutputStream out = null;
try {
in = getBaseContext().getResources().openRawResource(array[a]); // Here "array" is actually and array holding the reference of apk files (eg. R.raw.firstApp)
out = new FileOutputStream(Environment.getExternalStorageDirectory().getPath()+"/"+names[a]+".apk"); // Here "names" is an array holding the names of your apk files (eg. "firstApp")
Log.e("Path" ,Environment.getExternalStorageDirectory().getPath());
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(Environment.getExternalStorageDirectory().getPath()+"/"+names[a]+".apk")), "application/vnd.android.package-archive");
startActivity(intent);
}catch(Exception e){
// deal with copying problem
}
}
这篇关于使用1 APK安装多个Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!