Game Development Reference
In-Depth Information
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 Internet 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 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, for example, in a
game that is controlled only by the accelerometer.
ï?® android.permission.ACCESS_COARSE_LOCATION : This is a very useful
permission as it allows you to get non-GPS-level access to things like the
country in which the user is located, which can be useful for language
defaults and analytics.
ï?® android.permission.NFC : This allows applications to perform I/O operations
over near field communication (NFC), which is useful for a variety of game
features involving the quick exchange of small amounts of information.
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. You can
specify many more permissions; we 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 source of
error. It manifests itself as a message in the device log, so it might survive undetected due to all
the clutter in the log. In a subsequent section we'll describe the log in more detail. Think about
the permissions your game will need, and specify them when you initially create the project.
Another thing to note is that, when a user installs your application, he or she will first be asked
to review all of the permissions your application requires. Many users will just skip over these
and happily install whatever they can get hold of. Some users are more conscious about their
decisions and will review the permissions in detail. If you request suspicious permissions, like
Search WWH ::




Custom Search