<permission-tree> & <permission-group> & <uses-permission> & <permission>

For example, an activity could be protected as follows:

<manifest . . . >
    <permission android:name="com.example.project.DEBIT_ACCT" . . . />
    <uses-permission android:name="com.example.project.DEBIT_ACCT" />
    . . .
    <application . . .>
        <activity android:name="com.example.project.FreneticActivity"
                  android:permission="com.example.project.DEBIT_ACCT"
                  . . . >
            . . .
        </activity>
    </application>
</manifest>

Note that, in this example, the DEBIT_ACCT permission is not only declared with the <permission>element, its use is also requested with the <uses-permission> element. Its use must be requested in order for other components of the application to launch the protected activity, even though the protection is imposed by the application itself.

<permission-tree>

SYNTAX:
<permission-tree android:icon="drawable resource"
                 android:label="string resource" ]
                 android:name="string" />
CONTAINED IN:
<manifest>
DESCRIPTION:
Declares the base name for a tree of permissions. The application takes ownership of all names within the tree. It can dynamically add new permissions to the tree by calling PackageManager.addPermission(). Names within the tree are separated by periods (' .'). For example, if the base name is  com.example.project.taxes, permissions like the following might be added:

com.example.project.taxes.CALCULATE 
com.example.project.taxes.deductions.MAKE_SOME_UP 
com.example.project.taxes.deductions.EXAGGERATE

Note that this element does not declare a permission itself, only a namespace in which further permissions can be placed. See the <permission> element for information on declaring permissions.

ATTRIBUTES:
android:icon
An icon representing all the permissions in the tree. This attribute must be set as a reference to a drawable resource containing the image definition.
android:label
A user-readable name for the group. As a convenience, the label can be directly set as a raw string for quick and dirty programming. However, when the application is ready to be published, it should be set as a reference to a string resource, so that it can be localized like other strings in the user interface.
android:name
The name that's at the base of the permission tree. It serves as a prefix to all permission names in the tree. Java-style scoping should be used to ensure that the name is unique. The name must have more than two period-separated segments in its path — for example, com.example.base is OK, but  com.example is not.
INTRODUCED IN:
API Level 1

语法(SYNTAX):

<permission-treeandroid:icon="drawable resource"
                 
android:label="string resource" ]
                 
android:
name="string"/>

被包含于(CONTAINED IN):

<manifest>

说明(DESCRIPTION):

这个元素用于声明权限树的根节点名称,应用程序持有树中定义的所有权限名称所对应的权限。通过调用PackageManager.addPermission()方法能够动态的来添加新的权限。树中的名称是通过”.”来分离的。例如:如果跟节点的名称是com.example.project.taxes,那么可以使用下面的格式来添加权限:

com.example.project.taxes.CALCULATE
com.example.project.taxes.deductions.MAKE_SOME_UP

com.example.project.taxes.deductions.EXAGGERATE

要注意的是,这个元素本身并不声明权限,它只是一个能够放置更多权限的命名空间。关于声明权限的更多信息,请看<permission>元素。

属性(ATTRIBUTES):

android:icon

这个属性定义了一个代表树中所有权限的图标。这个属性必须要引用一个包含图片定义的可绘制资源来设置。

android:label

给权限树定义一个用户可读的名称。为了开发应用程序方便,可以直接使用原生的字符串来设置这个属性,但是,当正式发布应用程序时,应该引用一个字符串资源来设置这个属性,以便它能够像用户界面中的其他属性一样能够被本地化。

android:name

这个属性定义了权限树根节点的名称。它被用于树中所有权限名称的前缀。应该使用Java样式命名规则,以确保名称的唯一性。在命名中必须要有两个以上的”.”来进行分离,例如:com.example.base是正确的,但com.example就是错误的。

被引入版本(INTRODUCED IN)

API Level 1


<permission-group>

SYNTAX:
<permission-group android:description="string resource"
                  android:icon="drawable resource"
                  android:label="string resource"
                  android:name="string" />
CONTAINED IN:
<manifest>
DESCRIPTION:
Declares a name for a logical grouping of related permissions. Individual permission join the group through the  permissionGroup attribute of the  <permission> element. Members of a group are presented together in the user interface.

Note that this element does not declare a permission itself, only a category in which permissions can be placed. See the <permission> element for element for information on declaring permissions and assigning them to groups.

ATTRIBUTES:
android:description
User-readable text that describes the group. The text should be longer and more explanatory than the label. This attribute must be set as a reference to a string resource. Unlike the label attribute, it cannot be a raw string.
android:icon
An icon representing the permission. This attribute must be set as a reference to a drawable resource containing the image definition.
android:label
A user-readable name for the group. As a convenience, the label can be directly set as a raw string while you're developing the application. However, when the application is ready to be published, it should be set as a reference to a string resource, so that it can be localized like other strings in the user interface.
android:name
The name of the group. This is the name that can be assigned to a  <permission> element's <permissionGroup> attribute.
INTRODUCED IN:
API Level 1

<uses-permission>

SYNTAX:
<uses-permission android:name="string"
        android:maxSdkVersion="integer" />
CONTAINED IN:
<manifest>
DESCRIPTION:
Requests a permission that the application must be granted in order for it to operate correctly. Permissions are granted by the user when the application is installed, not while it's running.

For more information on permissions, see thePermissions section in the introduction and the separate Security and Permissions document. A list of permissions defined by the base platform can be found at android.Manifest.permission.

ATTRIBUTES:
android:name
The name of the permission. It can be a permission defined by the application with the  <permission>element, a permission defined by another application, or one of the standard system permissions, such as " android.permission.CAMERA" or " android.permission.READ_CONTACTS". As these examples show, a permission name typically includes the package name as a prefix.
android:maxSdkVersion
The highest API level at which this permission should be granted to your app. Setting this attribute is useful if the permission your app requires is no longer needed beginning at a certain API level.

For example, beginning with Android 4.4 (API level 19), it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided bygetExternalFilesDir()). However, the permission is required for API level 18 and lower. So you can declare that this permission is needed only up to API level 18 with a declaration such as this:

<uses-permission
     android:name="android.permission.WRITE_EXTERNAL_STORAGE"
     android:maxSdkVersion="18" />

This way, beginning with API level 19, the system will no longer grant your app theWRITE_EXTERNAL_STORAGE permission.

INTRODUCED IN:
API Level 1

<permission>

SYNTAX:
<permission android:description="string resource"
            android:icon="drawable resource"
            android:label="string resource"
            android:name="string"
            android:permissionGroup="string"
            android:protectionLevel=["normal" | "dangerous" | 
                                     "signature" | "signatureOrSystem"] />
CONTAINED IN:
<manifest>
DESCRIPTION:
Declares a security permission that can be used to limit access to specific components or features of this or other applications. See the  Permissions section in the introduction, and the  Security and Permissions document for more information on how permissions work.
ATTRIBUTES:
android:description
A user-readable description of the permission, longer and more informative than the label. It may be displayed to explain the permission to the user — for example, when the user is asked whether to grant the permission to another application.

This attribute must be set as a reference to a string resource; unlike the label attribute, it cannot be a raw string.

android:icon
A reference to a drawable resource for an icon that represents the permission.
android:label
A name for the permission, one that can be displayed to users.

As a convenience, the label can be directly set as a raw string while you're developing the application. However, when the application is ready to be published, it should be set as a reference to a string resource, so that it can be localized like other strings in the user interface.

android:name
The name of the permission. This is the name that will be used in code to refer to the permission — for example, in a  <uses-permission> element and the  permission attributes of application components.

The name must be unique, so it should use Java-style scoping — for example, "com.example.project.PERMITTED_ACTION".

android:permissionGroup
Assigns this permission to a group. The value of this attribute is the name of the group, which must be declared with the  <permission-group> element in this or another application. If this attribute is not set, the permission does not belong to a group.
android:protectionLevel
Characterizes the potential risk implied in the permission and indicates the procedure the system should follow when determining whether or not to grant the permission to an application requesting it. The value can be set to one of the following strings:
Value Meaning
"normal" The default value. A lower-risk permission that gives requesting applications access to isolated application-level features, with minimal risk to other applications, the system, or the user. The system automatically grants this type of permission to a requesting application at installation, without asking for the user's explicit approval (though the user always has the option to review these permissions before installing).
"dangerous" A higher-risk permission that would give a requesting application access to private user data or control over the device that can negatively impact the user. Because this type of permission introduces potential risk, the system may not automatically grant it to the requesting application. For example, any dangerous permissions requested by an application may be displayed to the user and require confirmation before proceeding, or some other approach may be taken to avoid the user automatically allowing the use of such facilities.
"signature" A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.
"signatureOrSystem" A permission that the system grants only to applications that are in the Android system image or that are signed with the same certificate as the application that declared the permission. Please avoid using this option, as the signature protection level should be sufficient for most needs and works regardless of exactly where applications are installed. The "signatureOrSystem" permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together.
INTRODUCED IN:
API Level 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值