Game Development Reference
In-Depth Information
First, we check whether the SD card is actually mounted. If not, we bail out early. Next, we get
the external storage directory and construct a new File instance that points to the file we are
going to create in the next statement. The writeTextFile() method uses standard Java I/O
classes to do its magic. If the file doesn't exist yet, this method will create it; otherwise, it will
overwrite an already existing file. After we successfully dump our test text to the file on the
external storage device, we read it in again and set it as the text of the TextView . As a final step,
we delete the file from external storage again. All of this is done with standard safety measures
in place that will report if something goes wrong by outputting an error message to the TextView .
Figure 4-11 shows the output of the activity.
Figure 4-11. Roger!
Here are the lessons to take away from this section:
ï?®
Don't mess with any files that don't belong to you. Your users will be angry if
you delete the photos of their last holiday.
ï?®
Always check whether the external storage device is mounted.
ï?®
Do not mess with any of the files on the external storage device!
Because it is very easy to delete all the files on the external storage device, you might think
twice before you install your next app from Google Play that requests permissions to the SD
card. The app has full control over your files once it's installed.
Search WWH ::




Custom Search