简体   繁体   English

Android 中的 sharedUserId 是什么,它是如何使用的?

[英]What is sharedUserId in Android, and how is it used?

我对 sharedUserID 感到困惑。sharedUserId 的用途是什么?如何使用?在 android 中在哪里使用?

By default, Android assigns a user id to an application.默认情况下,Android 会为应用程序分配一个用户 ID。 It is the unique id for your application and means that nobody except the user with this id can reach your application's resources.它是您的应用程序的唯一 ID,意味着除了具有此 ID 的用户之外,没有人可以访问您的应用程序资源。 You cannot access the data of an other application or run it in your current process.您无法访问其他应用程序的数据或在当前进程中运行它。 when, from an activity, an activity of another application is called android passes the control to the new activity called and they run in totally different processes.当从一个活动中,另一个应用程序的活动被调用时,android 会将控制权传递给被调用的新活动,并且它们在完全不同的进程中运行。

However, in your manifest file, you can explicitly identify a user id for your application.但是,在清单文件中,您可以明确标识应用程序的用户 ID。 When you declare the same user id for more than one application, they can reach each other's resources (data fields, views, etc.).当您为多个应用程序声明相同的用户 ID 时,它们可以访问彼此的资源(数据字段、视图等)。 You can display data from another application or run it in your process.您可以显示来自另一个应用程序的数据或在您的进程中运行它。

this is how you use it: from http://developer.android.com/guide/topics/manifest/manifest-element.html这是你如何使用它:来自http://developer.android.com/guide/topics/manifest/manifest-element.html

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="string"
    android:sharedUserId="string"
    android:sharedUserLabel="string resource" 
    android:versionCode="integer"
    android:versionName="string"
    android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
    . . .</manifest>

SharedUserId is used to share the data,processes etc between two or more applications. SharedUserId 用于在两个或多个应用程序之间共享数据、进程等。 It is defined in AndroidManifest.xml like,它在 AndroidManifest.xml 中定义,例如,

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:sharedUserId="android.uid.shared"
    android:sharedUserLabel="@string/sharedUserLabel"
    ...>

and define the shared parameter in Android.mk for that app, like并在 Android.mk 中为该应用定义共享参数,例如

LOCAL_CERTIFICATE := shared

Hope its helpful to you.希望对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM