Android 一个安装两个应用程序的 .apk 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10682576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
One .apk file that installs two apps
提问by MattTheHack
This is a question concerning android applications with two different .apks (or two apps contained in the one .apk file)
这是一个关于具有两个不同 .apk 的 android 应用程序(或包含在一个 .apk 文件中的两个应用程序)的问题
I have two apps which do completely different things but are related, say one is a standard user app and one is an admin app. But a user can be both a user and an admin. I am wondering is it possible for me to create one .apk file that installs two applications to the phone? And how would I got about this?
我有两个应用程序,它们做完全不同的事情但相互关联,比如一个是标准用户应用程序,一个是管理应用程序。但用户既可以是用户,也可以是管理员。我想知道我是否可以创建一个 .apk 文件来在手机上安装两个应用程序?我怎么会得到这个?
Thanks, Matt
谢谢,马特
采纳答案by Nanne
It depends on your definition of "application". You cannot install 2 applications if you use the more official definition, as you can have only 1 <application>
in your manifest.xml
这取决于您对“应用程序”的定义。如果使用更多的官方定义,则无法安装2个应用程序,因为你只能有1个<application>
在你的manifest.xml
You can define several activities in your manifest.xml
, and they can do seperate things, so in that way YOU CAN have 2 things a person might describe as "application" in one APK
您可以在您的manifest.xml
.APK
Just define multiple activities and use those could be defined as an option, but it depends on your definition of 'application', but in this case I'd say it would work
只需定义多个活动并使用它们就可以定义为一个选项,但这取决于您对“应用程序”的定义,但在这种情况下,我会说它会起作用
回答by user1364368
You can have two activity elements in the same manifest file, which have both the intent filter with action=MAINand category=LAUNCHER. Further, you have also to use the attribute "android:taskAffinity" for both activity elements (see also here):
您可以在同一个清单文件中有两个活动元素,它们都具有action=MAIN和category=LAUNCHER的意图过滤器。此外,您还必须为两个活动元素使用属性“ android:taskAffinity”(另请参见此处):
<application android:allowBackup="true"
android:icon="@drawable/main_icon"
android:label="@string/main_name"
android:theme="@style/AppTheme" >
<activity android:name="com.foobar.MyActivity2"
android:taskAffinity="com.foobar.MyActivity2"
android:icon="@drawable/icon1"
android:label="@string/name1" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.foobar.MyActivity2"
android:taskAffinity="com.foobar.MyActivity2"
android:icon="@drawable/icon1"
android:label="@string/name2" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When the APK file with this manifest is installed on a device, it will create two icons on the homescreen. The title of these icons will be taken from the attributes android:label, and the icons will be taken from the attributes android:icon. In the list of apps under "Settings | Apps"you'll see the name & icon defined by the attributes of the application tag. When you choose "uninstall" for this entry in the list of apps, then both "apps" will be removed from the device.
当带有此清单的 APK 文件安装在设备上时,它会在主屏幕上创建两个图标。这些图标的标题将从属性android:label 中获取,图标将从属性android:icon 中获取。在“设置|应用程序”下的应用程序列表中,您将看到由应用程序标签的属性定义的名称和图标。当您在应用列表中为该条目选择“卸载”时,这两个“应用”都将从设备中删除。
回答by shkschneider
You should either build 2 APKsare use APK Expansion Files.
您应该构建2 个 APK并使用APK 扩展文件。
Btw, this is a security measure.
顺便说一句,这是一项安全措施。