问题描述
我有两个单独的应用程序.目前我能够单独安装它们.我想知道如何使用单个APK安装它们.
我希望能够拥有两个应用程序仍然彼此独立运行,但我想能够将它们包装在一起.
当用户进入Google Play商店时,他们看到一个应用程序,但它实际上安装了两个应用程序.
谢谢, 杰夫
推荐答案
您可以在清单文件中定义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文件放在构建文件夹中的"原始"文件夹中.并将它们推在一起,这些应用程序将向用户显示对话框,以便询问权限,如果用户允许,将安装.
以下是要执行以下操作的代码:
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 } }
其他推荐答案
谢谢您的建议. 我能够通过以下方式解决问题,注意,我无法发布链接以来,我留下了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-than-one-toolsreplace-in-android-manifest-application. developer.android.com/studio/build/manifest-merge.html#inspect_the_mong_manifest_and_find_conflics
更新proguard-rules.pro文件: -keepAttributes enclaseMethod
- 在更新Android Studio后的Gradle Build中的错误使用log4j
在Gradle中添加对主要活动应用程序的依赖性: 编译项目(':myserviceApp')
问题描述
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.
This way when a user goes to the google play store they see one app, but it actually install both the apps.
Thanks, Jeff
推荐答案
you can define 2 luncher activity in your manifest file like bellow the result is what you want:
<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>
其他推荐答案
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 } }
其他推荐答案
Thank you for the advice. I was able to solve the issue by following, note I am leaving out the https part since I am unable to post links: Create a main activity project. Create another project for a service. Convert the service application to a library: developer.android.com/studio/projects/android-library.html#AddDependency
Fix any merge manifest issues: developer.android.com/studio/build/manifest-merge.html stackoverflow.com/questions/39178764/how-to-add-more-than-one-toolsreplace-in-android-manifest-application developer.android.com/studio/build/manifest-merge.html#inspect_the_merged_manifest_and_find_conflicts
Update the proguard-rules.pro files: -keepattributes EnclosingMethod
-Error in gradle build after updating Android Studio with log4j
Add a dependency to the main activity application in gradle: Compile project (':myserviceapp')