The <uses-permission> Element

我们现在告别<application>元素,回到<manifest>中定义的子元素,<uses-permission>就是我们接下来要讨论的其中一个元素。

Android有一个精心设计的安全模型。每一个应用都有其自己Linux用户和群组,在单独的进程和VM上运行,不能影响到其他应用。android同时也限定了系统资源的使用,像网络设备,SD卡,录音设备等。如果你的应用希望去使用任何系统资源,我们必须去申请Android的权限。这就是<uses-permission>元素的作用。

一个权限通常有以下格式,用一个名字为name 的字符串去指导我们希望使用的权限。

<uses-permission android:name="string"/>

这有一些可能会使用到的权限名:

android.permission.RECORD_AUDIO: 它允许我们使用录音设备。

android.permission.INTERNET: 它允许我们使用全部的networking APIs,举个例子,从网上得到一个图片或者更新网上的最高

分数。

android.permission.WRITE_EXTERNAL_STORAGE:它允许我们去读写外部存储设备,通常是设备的SD卡。

android.permission.WAKE_LOCK:它允许我们去锁定一个所谓的wake lock,使用wake lock我们可以避免在进行游戏的时候设

备休眠(在屏幕长时间没有被触屏时)。举个例子,这种情况何能出现在只是用加速传感器的时候。

想要获得networking APIs的使用权限,我们指定如下的元素作为 <manifest>的子元素。

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

如果还需要添加其他的元素,我们只需简单的添加更多的<uses-permission>就行了。你还有很多其他的权限可以指定,我再次

建议你去查询Android官方文档。我们只需要使用到刚才我们讨论的哪几个元素就行了。

忘记去添加一些如使用SD卡的权限会产生一个公共的错误,manifests在LogCat里面有消息,但是可能不会在杂乱的

LogCat当中被发现。思考什么权限是游戏需要的,然后在开始游戏开发之前指定它们。

另一方面需要注意的是,当用户安装你的应用的时候,用户会先游览应用所需要的权限。或许有些用户会跳过这些,然后开开

心心的把应用安装上,不管他们会不会着道。另外一些用户可能会有意识的去游览权限。如果你的应用带有一些敏感权限,像使

发送大量的短信或者得到使用者的位置,你就可能会在google market收到不好的评价。   如果你使用了一个有问题的敏感权限,

就去告诉用户你为什么要使用它。最好的办法是去避免使用这些敏感权限。

下一个是<uses-feature>

附上原文:

The <uses-permission> Element 
We are leaving the <application> element now and coming back to elements we define
as children of the <manifest> element. One of these elements is the <uses-permission>
element.

Android has an elaborate security model. Each application is run in its own process and
VM, with its own Linux user and group, and cannot influence other applications. Android
also restricts the use of system resources, such as networking facilities, the SD card,
and the audio-recording hardware. If our application wants to use any of these system
resources, we have to ask for permission. This is done with the <uses-permission>
element.

A permission always has the following form, where string specifies the name of the
permission we want to be granted:

<uses-permission android:name="string"/> 
Here are a few permission names that might come in handy: 
android.permission.RECORD_AUDIO: This grants us access to the
audio-recording hardware.

android.permission.INTERNET: This grants us access to all the
networking APIs so we can, for example, fetch an image from the Net
or upload high-scores.

android.permission.WRITE_EXTERNAL_STORAGE: This allows us to read
and write files on the external storage, usually the SD card of the
device.

android.permission.WAKE_LOCK: This allows us to acquire a so-called 
wake lock. With this wake lock we can keep the device from going to 
sleep if the screen hasn’t been touched for some time. This could 
happen in a game that is controlled only by the accelerometer, for 
example.

To get access to the networking APIs, we’d thus specify the following element as a child 
of the <manifest> element:

<uses-permission android:name="android.permission.INTERNET"/> 
For any additional permissions, we simply add more <uses-permission> elements. There 
are many more permissions you can specify; I again refer you to the official Android 
documentation. We’ll only need the set just discussed.

Forgetting to add a permission for something like accessing the SD card is a common 
error source that manifests itself as a message in LogCat, which might survive 
undetected due to all the clutter in LogCat. Think about the permissions your game will 
need and specify them when you create the project initially.

Another thing to notice is that when a user installs your application, she will first be 
asked to review all the permissions your application wants. Many users will just skip 
reading those and happily install whatever they can get ahold of. Some users are more 
conscious about their decisions and will review the permissions in detail. If you request 
suspicious permissions, like the ability to send out costly SMS messages or get a user’s 
location, you may receive some nasty feedback from users in the Comments section for 
your application in the market. If you use one of those problematic permissions, then tell 
the user why you’re using it in your application description. The best thing is to avoid 
those permissions in the first place, though.

AndroidManifest.xml 详解 (四) 之uses-permission的更多相关文章

  1. AndroidManifest.xml详解(上)

    本文编辑整理自:http://blog.163.com/hero_213/blog/static/39891214201242835410742/ 一.关于AndroidManifest.xml    ...

  2. Android 之 AndroidManifest.xml 详解(二)

    [10]<activity> Activity活动组件(即界面控制器组件)的声明标签,Android应用中的每一个Activity都必须在AndroidManifest.xml配置文件中声 ...

  3. AndroidManifest.xml详解

    一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...

  4. Android AndroidManifest.xml详解

    AndroidManifest.xml简述: AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activitie ...

  5. Android 之 AndroidManifest.xml 详解(一)

    当Android启动一个应用程序组件之前,它必须知道哪些个组件是存在的,所以开发人员在开发过程中,必须将应用程序中出现的组件一一在AndroidManifest.xml文件中" 声明 &qu ...

  6. AndroidManifest.xml详解(下)

    本文编辑整理自:http://blog.163.com/hero_213/blog/static/39891214201242835410742/ 八.第三层<activity-alias> ...

  7. AndroidManifest.xml 详解

    第1部分 标签库+包路径+版本控制 <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...

  8. [android] AndroidManifest.xml 详解

    第1部分 标签库+包路径+版本控制 <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...

  9. 【AndroidManifest.xml详解】Manifest属性之sharedUserId、sharedUserLabel

    http://blog.csdn.net/wirelessqa/article/details/8581652 android:sharedUserId 当APK安装的时候,userid这个标志就会产 ...

随机推荐

  1. echart图表控件配置入门(二)常用图表数据动态绑定

    上一节 <echart图表控件配置入门(一)>介绍了echarts图表控件的入门配置,使开发人员可以快速搭建出一个静态的图表.但是在实际开发过程这还是不够的,不可能所有的图表控件都是静态数 ...

  2. 如何引用CSS样式表

      如何使用样式 当浏览器读到一个样式表,它就会按照这个样式表来对文档进行格式化.有以下三种方式来插入样式表: 1.外部样式表 当样式需要被应用到很多页面的时候,外部样式表将是理想的选择.使用外部样式 ...

  3. 记录一下JS正则的坑

    JS正则的单行模式有点问题 总之 . 符号匹配换行符号会有问题 暂时的解决方案是 html = html.replace(/[\r\n]/g,""); 附加一个 html = ht ...

  4. cubieboard中使用py-kms与dnsmasq搭建局域网内全自动KMS激活环境

    众所周知,KMS激活方式是当前广大网民“试用”windows,office的最广泛的激活方式.几乎可以用于微软的全线产品. 但是在本机使用KMS类的激活工具总是有些不放心,一方面每隔180天都要重新激 ...

  5. PV3D学习笔记-导入DAE模型

      网上关于PV3D导入DAE模型的例子都非常多,可惜我研究了半天,一个都没成功,或者是破面问题,或者是贴图不显示,再或者贴图乱掉了.今天晚上终于搞定,心得发上来. 制作模型的软件是SketchUp ...

  6. c++声明与定义

    c++声明与定义 声明是将一个名称引入程序.定义提供了一个实体在程序中的唯一描述.声明和定义有时是同时存在的. 如 int  a; extern int b=1; 只有当extern中不存在初始化才是 ...

  7. cocos中添加显示文字的三种方式(CCLabelTTF 、CCLabelBMFont 和CCLabelAtlas)

    CCLabelTTF CCLabelTTF 每次调用 setString (即改变文字)的时候,一个新的OPENGL 纹理将会被创建..这意味着setString 和创建一个新的标签一样慢. 这个类使 ...

  8. 关于PCB 3D 模型的快速导入方法

    altium designer中创建的3D library 只能查看3D效果,并没有其他功能,经测试在原理图编辑界面通过给元件添加 PCB 3D 并不能真正添加3D模型,这样添加根本没有效果(显示不出 ...

  9. 给windows 7安装文件添加USB3.0驱动

    给Air安装win7进入语言与区域选择之后,发现键盘触摸板都失灵.   原因:新款的 Macbook Air 2013 因为使用了 USB3.0 端口键盘和触摸板设备,所以在安装 Windows 7 ...

  10. IP地址转换成Long型数字的算法

    在应用程序开发中,涉及到IP地址的存储,大部分开发人员都将其存为String(或文本类型).能否将固定格式为m.n.x.y的IP地址转换成 Long型的数字呢?答案是肯定的.在数据库层面,可以直接将结 ...