您可以通过将AndroidManifest.xml文件中的sharedUserLabel
和sharedUserId
设置为相同的值来完成此操作。举个例子,如果我有以下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">
那么他们都将共享相同的用户。
但我强烈建议不要这样做。绝大多数的应用程序不应该这样做;它只适用于特殊情况。使用它会导致大多数开发人员不应该对自己造成的行为上的细微差异(例如所有应用程序共享相同的权限)。 – hackbod 2011-06-15 07:50:25
这太棒了!但是有没有办法从第三个应用程序获取具有相同shareUserId的应用程序。我的意思是我希望检测2个应用程序具有相同的sharedUserId – AbhishekB 2012-10-30 14:49:46
请看http://developer.android.com/reference/android/content/pm/ApplicationInfo.html:这两个应用程序的uid都是相同的。 – Femi 2012-10-30 18:26:26