"Androidmanifest.xml detailed" manifest attribute Shareduserid, Shareduserlabel

Source: Internet
Author: User

Http://blog.csdn.net/wirelessqa/article/details/8581652android:sharedUserId

When the APK is installed, the UserID will be created. The ID will no longer change over the entire life cycle of the device. The same app package may have different userid on different devices, and it is important that each app package has its own userid on a given device.

Features of the UserID:

1. Identity 2 as the APK identity. UserID corresponds to a Linux user, so accessing data between different apk (users) is forbidden by default.

What should you do if you want to access data between different apk?

Android provides us with two ways of exchanging data:

One is to use share Preference. /Content Provider

The APK is read by specifying the interface and data for the other apk, and the developer needs to implement the interface and specify share data. "This method is explained in detail later."

The second is to configure the same userid in the config file manifest

By sharing the UserID, users with the same userid can be configured to run in the same process, so the default is to access arbitrary data with each other

It can also be configured as a different process, accessing each other's databases and files as if they were accessing their own data.

Example:

Application 1:com.wirelessqa.sqlite

01 <manifestxmlns:android="http://schemas.android.com/apk/res/android"
02     package="com.wirelessqa.sqlite"
03
04     android:versionCode="1"
05
06     android:versionName="1.0"
07
08     android:sharedUserId="wirelessqa.com"
09
10     >

Application 2:com.wirelessqa.activity

1 <manifestxmlns:android="http://schemas.android.com/apk/res/android"
2     package="com.wirelessqa.activity"
3     android:versionCode="1"
4     android:versionName="1.0"
5     android:sharedUserId="wirelessqa.com"
6     >

Both applications have the same userid, which is wirelessqa.com, so two applications share the UserID, what if 1 want to access 2 of the data?

Content content = this.createpackagecontent ("com.wirelessqa.activity", content.content_ignore_security);

The content can be used to obtain the resources in application 2, including: Database, preference, resource files, etc.

Attention:

Based on security considerations, two packages need to have the same signature, otherwise there is no validation, once the application set up Shareuserid, when the program is cracked, other applications can also access our data, data insecure settings sharing is not much significance.

Summarize:

If you want to share data between different apk, the following conditions are true:

1.APK signatures must be the same

2.android:shareuserid must have the same value

3. If you want to run in the same operation, you must set the Android:process value to be the same.

Application set all components of an application to run in a thread

View Source
1 <applicationandroid:allowBackup="true" android:icon="@drawable/ic_launcher"android:label="@string/app_name"
2
3         android:theme="@style/AppTheme"android:process="wqa.com">

Android:shareduserlabel

This attribute defines a user -readable label for the shared UserID. This tag must be set with a string resource and cannot be used as a native string.

This attribute is introduced in API Level 3 and is only meaningful if the Shareduserid property is set.

"Androidmanifest.xml detailed" manifest attribute Shareduserid, Shareduserlabel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.