1.<uses-permission>:

官方描述:

  1. If an application needs access to a feature protected by a permission, it must declare that it requires that permission with a <uses-permission>
    element in the manifest. Then, when the application is installed on the device, the installer determines whether or not to grant the requested
    permission by checking the authorities that signed the application's certificates and, in some cases, asking the user. If the permission is granted,
    the application is able to use the protected features. If not, its attempts to access those features will simply fail without any notification to the user.

如果一个应用需要访问一个受permission保护的特性,那这个应用必须在 manifest中以 <uses-permission> 节点声明它所需要的权限。当这个应用安装在设备的时候,

安装器会决定是否授予它所声明的权限,这有时候会询问用户。如果权限被授予了,这个应用才能使用受保护的特性,否则的话, 访问失败并且 不会 通知用户。

注意:不一定是调用其他应用程序才要声明 <uses-permission> ,有时甚至调用自己应用的程序的组件都要声明!!!(下面的例子会说到)

2. <permission>:

  1. An application can also protect its own components (activities, services, broadcast receivers, and content providers) with permissions.
    It can employ any of the permissions defined by Android (listed in android.Manifest.permission ) or declared by other applications. Or
    it can define its own. A new permission is declared with the <permission> element.

一个应用程序也能用 permissions 保护自己的组件,它能使用android系统定义的或者其他应用定义的又或者自身应用定义的permissions,如果要想定义一个新的permission,

可以用 <permission>  节点来定义。如下:

  1. <permission android:description="string resource"
  2. android:icon="drawable resource"
  3. android:label="string resource"
  4. android:name="string"
  5. android:permissionGroup="string"
  6. android:protectionLevel=["normal" | "dangerous" |
  7. "signature" | "signatureOrSystem"] />

For example, an activity could be protected as follows:

  1. <manifest . . . >
  2. <permission android:name="com.example.project.DEBIT_ACCT" . . . />
  3. <uses-permission android:name="com.example.project.DEBIT_ACCT" />
  4. . . .
  5. <application . . .>
  6. <activity android:name="com.example.project.FreneticActivity"
  7. android:permission="com.example.project.DEBIT_ACCT"
  8. . . . >
  9. . . .
  10. </activity>
  11. </application>
  12. </manifest>
  1. 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.
  2.  
  3. If, in the same example, the permission attribute was set to a permission declared elsewhere (such as android.permission.CALL_EMERGENCY_NUMBERS , it would not have been
    necessary to declare it again with a <permission> element. However, it would still have been necessary to request its use with <uses-permission> .

注意的是,在这个例子中, DEBIT_ACCT这个权限不仅在<permission>中声明,并且也在<uses-permission>中声明,要想在这应用的其他组件启动这个受保护的activity时,

在<uses-permission>中声明DEBIT_ACCT这个权限是必须的,即使这个保护是这个应用本身加上的。(这印证了上面第1点说的)。

注意,如果添加的permission是其他地方定义的,那就没必要再<permission>声明一次,但是,仍然用<uses-permission>声明这个权限。

参考:

http://developer.android.com/guide/topics/manifest/manifest-intro.html#perms

http://berdy.iteye.com/blog/1782854

http://blog.csdn.net/lilu_leo/article/details/6940941

uses-permission和permission详解的更多相关文章

  1. Linux—账号管理及命令使用详解

    关注微信公众号:CodingTechWork,一起学习进步. 引言   在Linux系统中,我们常常会看到目录或文件的所属关系: [root@linux01 ~]# ll -d test.sh -rw ...

  2. kafka启动时出现FATAL Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer) java.io.IOException: Permission denied错误解决办法(图文详解)

    首先,说明,我kafk的server.properties是 kafka的server.properties配置文件参考示范(图文详解)(多种方式) 问题详情 然后,我启动时,出现如下 [hadoop ...

  3. Shiro基础知识03----shiro授权(编程式授权),Permission详解,授权流程(zz)

    授权,也叫访问控制,即在应用中控制谁能访问哪些资源(如访问页面/编辑数据/页面操作等).  在权限认证中,最核心的是:主体/用户(Subject).权限(Permission).角色(Role).资源 ...

  4. Permission 使用详解

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  5. Android Notification 详解(一)——基本操作

    Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...

  6. Android Notification 详解——基本操作

    Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...

  7. Android PopupWindow Dialog 关于 is your activity running 崩溃详解

    Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...

  8. Android 网络框架之Retrofit2使用详解及从源码中解析原理

    就目前来说Retrofit2使用的已相当的广泛,那么我们先来了解下两个问题: 1 . 什么是Retrofit? Retrofit是针对于Android/Java的.基于okHttp的.一种轻量级且安全 ...

  9. Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解

    转载:http://freeloda.blog.51cto.com/2033581/1288553 大纲 一.前言 二.环境准备 三.安装与配置Nginx 四.Nginx之反向代理 五.Nginx之负 ...

  10. APP漏洞扫描器之本地拒绝服务检测详解

    APP漏洞扫描器之本地拒绝服务检测详解 阿里聚安全的Android应用漏洞扫描器有一个检测项是本地拒绝服务漏洞的检测,采用的是静态分析加动态模糊测试的方法来检测,检测结果准确全面.本文将讲一下应用漏洞 ...

随机推荐

  1. hdu 1717

    小数化分数2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  2. CentOS 7 使用iptables 开放端口

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service system ...

  3. 汉若塔系列续:汉诺塔VIII、汉诺塔IX、汉诺塔X。

    汉诺塔VIII,在经典汉若塔问题上,问n个盘子的情况下,移动m次以后,是什么状态.(与第七代互为逆命题) 我的思路:本质还是dfs,但是用m的值来指引方向,每搜一层确定第i个盘子在哪个塔,o(n)的算 ...

  4. Python 和 Elasticsearch 构建简易搜索

    Python 和 Elasticsearch 构建简易搜索 作者:白宁超 2019年5月24日17:22:41 导读:件开发最大的麻烦事之一就是环境配置,操作系统设置,各种库和组件的安装.只有它们都正 ...

  5. Codeforces Gym 100418K Cards 组合数学

    CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  6. java通过反射获取bean字段注解@Column中的信息

    直接上代码吧: Field field; Field[] fields=clas.getDeclaredFields(); for (int i = 0; i <fields.length ; ...

  7. NOIP前必须记住的30句话

    NOIP前必须记住的30句话 1.比赛前一天晚上请准备好你的各种证件,事先查好去往考场的路线2.比赛之前请先调整你的屏幕分辨率到你喜欢的大小3.比赛之前请把编译器的字体调为你平时惯用的字体,尤其是注意 ...

  8. Linux Kernel - Debug Guide (Linux内核调试指南 )

    http://blog.csdn.net/blizmax6/article/details/6747601 linux内核调试指南 一些前言 作者前言 知识从哪里来 为什么撰写本文档 为什么需要汇编级 ...

  9. 【flyway】Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' def

    报错如下: "2018-03-20 12:58:09.585 WARN 18026 — [ restartedMain] ConfigServletWebServerApplicationC ...

  10. MySQL的字符编码体系(一)——数据存储编码

    安装MySQL好多次了,每次都会纠结于数据库的字符编码配置,所以我决定这一次彻底把它理清. MySQL的字符编码结构比較细,它慷慨向分为两个部分:数据存储编码和传输数据编码.本篇讨论数据存储编码部分, ...