30.04.2013 Views

Android - CommonsWare

Android - CommonsWare

Android - CommonsWare

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Requesting and Requiring Permissions<br />

depending on if something else is catching and trying to handle that<br />

exception. Note that you will only fail on a permission check if you forgot to<br />

ask for the permission – it is impossible for your application to be running<br />

and not have been granted your requested permissions.<br />

Halt! Who Goes There?<br />

The other side of the coin, of course, is to secure your own application. If<br />

your application is merely activities and intent receivers, security may be<br />

just an “outbound” thing, where you request the right to use resources of<br />

other applications. If, on the other hand, you put content providers or<br />

services in your application, you will want to implement “inbound” security<br />

to control which applications can do what with the data.<br />

Note that the issue here is less about whether other applications might<br />

“mess up” your data, but rather about privacy of the user's information or<br />

use of services that might incur expense. That is where the stock<br />

permissions for built-in <strong>Android</strong> applications are focused – can you read or<br />

modify contacts, can you send SMS, etc. If your application does not store<br />

information that might be considered private, security is less an issue. If, on<br />

the other hand, your application stores private data, such as medical<br />

information, security is much more important.<br />

The first step to securing your own application using permissions is to<br />

declare said permissions, once again in the <strong>Android</strong>Manifest.xml file. In this<br />

case, instead of uses-permission, you add permission elements. Once again,<br />

you can have zero or more permission elements, all as direct children of the<br />

root manifest element.<br />

Declaring a permission is slightly more complicated than using a<br />

permission. There are three pieces of information you need to supply:<br />

1. The symbolic name of the permission. To keep your permissions<br />

from colliding with those from other applications, you should use<br />

your application's Java namespace as a prefix<br />

365<br />

Subscribe to updates at http://commonsware.com Special Creative Commons BY-SA 3.0 License Edition

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!