2011-06-15 107 views
13

http://developer.android.com/guide/topics/fundamentals.html两款Android应用使用相同的用户ID

这是可能的两个应用程序共享相同的Linux 的用户ID,在这种情况下,他们能够互相访问对方的文件安排。为了节省系统资源,具有相同用户ID的应用程序也可以安排在相同的Linux进程中运行并共享相同的VM( 应用程序也必须使用相同的证书进行签名)。

我们如何才能为两个应用程序实现相同的用户ID?任何示例?

回答

21

您可以通过将AndroidManifest.xml文件中的sharedUserLabelsharedUserId设置为相同的值来完成此操作。举个例子,如果我有以下2个清单文件(我只包括开头):

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     android:sharedUserLabel="@string/label_shared_user" android:sharedUserId="com.example" package="com.example.package1" android:versionName="2.0.0" android:versionCode="2"> 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     android:sharedUserLabel="@string/label_shared_user" android:sharedUserId="com.example" package="com.example.package2" android:versionName="1.0.0" android:versionCode="1"> 

那么他们都将共享相同的用户。

+6

但我强烈建议不要这样做。绝大多数的应用程序不应该这样做;它只适用于特殊情况。使用它会导致大多数开发人员不应该对自己造成的行为上的细微差异(例如所有应用程序共享相同的权限)。 – hackbod 2011-06-15 07:50:25

+0

这太棒了!但是有没有办法从第三个应用程序获取具有相同shareUserId的应用程序。我的意思是我希望检测2个应用程序具有相同的sharedUserId – AbhishekB 2012-10-30 14:49:46

+0

请看http://developer.android.com/reference/android/content/pm/ApplicationInfo.html:这两个应用程序的uid都是相同的。 – Femi 2012-10-30 18:26:26

相关问题