permission-group 的使用详解

permission-group 标签用于将多个权限归类到特定类别下,如 Android 中的 SMS 相关权限被归类到 android.permission-group.MESSAGES,以便在应用使用这些权限时显示统一图标和名称。它不能直接作为权限的组合,例如 SEND_SMS 权限因 android:permissionFlags="costsMoney" 而被视为付费权限。

The tag permission-group is just used to group one or more permissions under a particular category. From the developer's site http://developer.android.com/guide/topics/manifest/permission-group-element.html

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.

For example, the messages related permissions, say android.permission.SEND_SMS, RECEIVE_SMS and all the permissions related to messages are grouped under android.permission-group.MESSAGES to have a common icon.

From AndroidManifest.xml of android sourcehttps://github.com/android/platform_frameworks_base/blob/master/core/res/AndroidManifest.xml

 <permission-group android:name="android.permission-group.MESSAGES"
    android:label="@string/permgrouplab_messages"
    android:icon="@drawable/perm_group_messages"
    android:description="@string/permgroupdesc_messages"
    android:permissionGroupFlags="personalInfo"
    android:priority="360"/>

  <!-- Allows an application to monitor incoming SMS messages, to record
     or perform processing on them. -->
<permission android:name="android.permission.RECEIVE_SMS"
    android:permissionGroup="android.permission-group.MESSAGES"
    android:protectionLevel="dangerous"
    android:label="@string/permlab_receiveSms"
    android:description="@string/permdesc_receiveSms" />

<!-- Allows an application to send SMS messages. -->
<permission android:name="android.permission.SEND_SMS"
    android:permissionGroup="android.permission-group.MESSAGES"
    android:protectionLevel="dangerous"
    android:permissionFlags="costsMoney"
    android:label="@string/permlab_sendSms"
    android:description="@string/permdesc_sendSms" />

Here, the android.permission-group.MESSAGES categorises these permissions under a common icon and name in permissions when your applications uses these permissions.

Give

<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

in a sample application to see the result. Those two permissions will be grouped into a common category.

Note the Receive and send sms categorised into a group

The costs money is because of the android:permissionFlags="costsMoney" in SEND_SMS permission. Hence permission-group is only used to categorise the permissions. It cannot be used as in to group one or more permissions.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值