使用 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屋!