Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用1个APK安装多个android应用程序_Android_Apk - Fatal编程技术网

使用1个APK安装多个android应用程序

使用1个APK安装多个android应用程序,android,apk,Android,Apk,我有两个独立的应用程序。目前我可以单独安装它们。我想知道如何使用单个APK安装它们 我希望这两个应用程序仍然能够独立运行,但我希望能够将它们打包在一起 这样,当用户进入google play商店时,他们会看到一个应用程序,但实际上它会同时安装这两个应用程序 谢谢, Jeff您可以在清单文件中定义2个午餐者活动,如下面所示。结果就是您想要的: <application android:allowBackup="true" android:icon="@mipm

我有两个独立的应用程序。目前我可以单独安装它们。我想知道如何使用单个APK安装它们


我希望这两个应用程序仍然能够独立运行,但我希望能够将它们打包在一起

这样,当用户进入google play商店时,他们会看到一个应用程序,但实际上它会同时安装这两个应用程序

谢谢,
Jeff

您可以在清单文件中定义2个午餐者活动,如下面所示。结果就是您想要的:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
        android:icon="@mipmap/ic_launcher">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity2"
        android:icon="@mipmap/ic_launcher">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

您不能直接安装两个应用程序而不向用户显示,您可以创建一个新应用程序,将2个apk文件放在build文件夹中的“raw”文件夹中。并将它们推到一起打开,这些应用程序将向用户显示一个对话框,询问权限,并在用户允许的情况下安装

下面是执行此操作的代码:

 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
        }
    }
for(inta=0;a谢谢你的建议。
我通过以下方式解决了这个问题,注意,我省略了https部分,因为我无法发布链接:
创建主活动项目。为服务创建另一个项目。将服务应用程序转换为库:
developer.android.com/studio/projects/android library.html#AddDependency

修复任何合并清单问题: developer.android.com/studio/build/manifest-merge.html stackoverflow.com/questions/39178764/how-to-add-more-one-toolsreplace-in-android-manifest-application developer.android.com/studio/build/manifest merge.html检查合并的清单和查找冲突

更新proguard-rules.pro文件: -keepattributes封闭方法

-

向gradle中的主活动应用程序添加依赖项:
编译项目(“:myserviceapp”)

“我希望这两个应用程序仍能彼此独立运行”--请从技术角度详细解释这意味着什么,以及如果所有这些功能都在一个应用程序中会有什么区别。第一个应用程序是将文档转换为PDF的应用程序。第二个应用程序是打印服务。两者都独立运行。它们都是独立的应用程序。在Google pl中ay store,我希望它们显示为第一个应用程序的名称。当下载并安装第一个应用程序时,我希望两个应用程序都安装。“它们是独立的应用程序”--为什么?再次说明,分离的技术原因是什么?由于明显的原因,您不可能想要什么(在您的场景中,替换“打印服务”和“恶意软件”)。事实上,IIRC,出于这个原因,你想要的是违反Play Store的服务条款。因此,从技术上讲,你可以在你的APK中有一个APK,然后提取并安装它(在用户授予你的应用程序安装其他应用程序的权利后,然后通过第二个APK的安装屏幕进行安装),不清楚为什么这样做是为了您或您的用户的最大利益。我看到另一个应用程序表现出这种行为。我安装了他们的单个应用程序,它安装了应用程序和打印服务。该应用程序只进行一次下载和安装,没有显示作为过程的一部分正在安装的第二个应用程序。安装应用程序后,我将看到s是应用程序的图标,当我转到“打印服务”设置时,我看到他们也安装了打印服务。我希望能够遵循相同的约定。您描述中的任何内容都不表示两个应用程序。您描述的是一个应用程序的预期结果,该应用程序恰好同时具有启动程序活动和打印服务ice。这对我有用。我已经创建了两个应用程序,并在将第一个应用程序作为库迁移到第二个应用程序上之后。接下来从库的
AndroidMenifest.xml
文件中删除
intent筛选器
,问题就解决了。谢谢。