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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9783765/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 07:37:34  来源:igfitidea点击:

What is sharedUserId in Android, and how is it used?

javaandroidandroid-intentandroid-emulatorandroid-ndk

提问by Bhargav Panchal

I am confused in sharedUserID.what is use of sharedUserId?How to use?Where to use in android?

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

采纳答案by Parthraj

SharedUserId is used to share the data,processes etc between two or more applications. It is defined in AndroidManifest.xml like,

SharedUserId 用于在两个或多个应用程序之间共享数据、进程等。它在 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.

希望对你有帮助。

回答by cagla

By default, Android assigns a user id to an application. It is the unique id for your application and means that nobody except the user with this id can reach your application's resources. 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 会为应用程序分配一个用户 ID。它是您的应用程序的唯一 ID,意味着除了具有此 ID 的用户之外,没有人可以访问您的应用程序资源。您无法访问其他应用程序的数据或在当前进程中运行它。当从一个活动中,另一个应用程序的活动被调用时,android 会将控制权传递给被调用的新活动,并且它们在完全不同的进程中运行。

However, in your manifest file, you can explicitly identify a user id for your application. When you declare the same user id for more than one application, they can reach each other's resources (data fields, views, etc.). You can display data from another application or run it in your process.

但是,在清单文件中,您可以明确标识应用程序的用户 ID。当您为多个应用程序声明相同的用户 ID 时,它们可以访问彼此的资源(数据字段、视图等)。您可以显示来自另一个应用程序的数据或在您的进程中运行它。

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>