Download mc-android-storage - Homepages | The University of Aberdeen

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Database model wikipedia , lookup

Transcript
Android Storage & SMS Apps
Mobile Computing
See Unlocking Android (Ch 5) for more details
Unless otherwise stated, images are from android sdk
Bruce Scharlau, University of Aberdeen, 2010
There are several options for
storage of data with Android
• We can put data into a preferences file.
• We can put data into a ‘normal’ file.
• We can send data across the network to a
service.
• We can use a local database on the
handset.
Bruce Scharlau, University of Aberdeen, 2010
Preference files are a
light-weight option
• Call Context.getSharedPreferences() to read
and write values as key-value pairs.
• Use Activity.getPreferences() with no name
to keep them private to the calling activity
These are not sharable across applications,
unless you expose them as a ‘content
provider’.
Bruce Scharlau, University of Aberdeen, 2010
We can write larger data to file
You can only access files available to the application
• You can either write to a new file, or to a preincluded file under res/raw/mydata
• To can read data from a file, call
Context.openFileInput() and pass it the local name
and path of the file. It returns a standard Java
FileInputStream object.
• To write to a file, call Context.openFileOutput() with
the name and path. It returns a FileOutputStream
object.
Bruce Scharlau, University of Aberdeen, 2010
File writing is similar to what
you’ve done before
Source: unlocking android, p 159
Bruce Scharlau, University of Aberdeen, 2010
We can place data elsewhere on
the network
Use a web service to store data elsewhere –
save photos to flickr, files to some other
app in the cloud.
Can save files automatically, or at user
discretion with time values, etc. (twitter,
email apps, or photo capture)
Bruce Scharlau, University of Aberdeen, 2010
We can also persist data to a db
• Android API uses the built-in SQLite db.
• Each db is private to the application. In
principle you could expose the data, if you
expose the application as a content
provider.
• All databases, SQLite and others, are
stored on the device in
/data/data/package_name/databases.
Bruce Scharlau, University of Aberdeen, 2010
Android Notepad tutorial uses
database
Useful db helper class for access and crud details
Bruce Scharlau, University of Aberdeen, 2010
Context Menu is special
Acquire context menu by holding down
selection key (long press on touch), which
then pops up context menu
Bruce Scharlau, University of Aberdeen, 2010
Unlocking Android db example
covers more complex example
Stores locations to database
within application as objects
Bruce Scharlau, University of Aberdeen, 2010
Unlocking Android app uses db
helper classes with sql
public static class Location {
Part of DBHelper class showing
Location object
public long id;
public long lastalert;
public int alertenabled;
public String zip;
// include city and region because geocode is expensive
public String city;
public String region;
public Location() {
}
Class also holds crud details to
map object to sql
public Location(final long id, final long lastalert, final int
alertenabled, final String zip,
final String city, final String region) {
this.id = id;
this.lastalert = lastalert;
this.alertenabled = alertenabled;
this.zip = zip;
this.city = city;
Source: unlocking android, code
this.region = region;
Bruce Scharlau, University of Aberdeen, 2010
}
Unlocking Android app maps
objects to sql for ease
public void insert(final Location location) {
ContentValues values = new ContentValues();
values.put("zip", location.zip);
values.put("city", location.city);
values.put("region", location.region);
values.put("lastalert", location.lastalert);
values.put("alertenabled", location.alertenabled);
this.db.insert(DBHelper.DB_TABLE, null, values);
}
Mapping makes
coding easier
public void update(final Location location) {
ContentValues values = new ContentValues();
values.put("zip", location.zip);
values.put("city", location.city);
values.put("region", location.region);
Source: unlocking android, code
values.put("lastalert", location.lastalert);
values.put("alertenabled", location.alertenabled);
this.db.update(DBHelper.DB_TABLE, values, "_id=" + location.id, null);
Bruce Scharlau, University of Aberdeen, 2010
}
SQLite provides advanced db
features
• There is transaction support
• You can use prepared statements based
on java.sql and set items as have done
before – faster and more secure
• You have a cursor to keep track of location
within a resultset
Bruce Scharlau, University of Aberdeen, 2010
Can map objects to db
Can read items from network as xml and
convert to objects, which map to db
Enables off network use and can sync later
when connected
Might be pushing limits of device though
with extra classes and memory usage
Bruce Scharlau, University of Aberdeen, 2010
Storage Summary
• Can use preferences for each app
• Can write/read files as with Java
• Can persist/read items over network
(when available)
• Can use SQLite one db per app
Bruce Scharlau, University of Aberdeen, 2010
SMS applications should not be
overlooked
Cheaper and faster to develop than GUI apps
Available to all handsets for wider usage
Faster to market for specific events
Bruce Scharlau, University of Aberdeen, 2010
There are wide variety of SMS
apps
• Notify customers that meal, prescription,
etc is available for collection
• Medical, dentist, etc appointment
reminders to prevent no-shows
• Order prescription refills, meals, special
offers – Hilton Hotels even do this
• Also use SMS to drive traffic to mobile
sites and increase customer sales
http://www.textsmsmarketing.com/sms-text-marketing-case-studies.php
Bruce Scharlau, University of Aberdeen, 2010
Also other usual contests, etc
•
•
•
•
•
SMS voting contests
Send photo to win prizes contests
Communicate with call centres via SMS
Query and reserve products via SMS
Scheduled SMS sending to coordinate
with other actions for business and
students
• Many more too
http://www.spotlightideas.co.uk/?p=4582
Bruce Scharlau, University of Aberdeen, 2010
SMS apps reach many people
• SMS is reliable and can be sent any time
• Supported by ALL mobile phones – can
reach about 50% of population, ie 3.3 bn
• Supports reverse billing – thus customer
pays for receiving new ringtone, etc that is
sent from you to them
http://www.developershome.com/sms/
Bruce Scharlau, University of Aberdeen, 2010
SMS apps can be easy to build
• The components are free to set up and
develop
• SMPPsim for simulating SMS center and
responses http://www.seleniumsoftware.com/downloads.html
• Use SMPP API for communicating with
SMS center http://smppapi.sourceforge.net/
• http://www.kannel.org/ provides an SMS
gateway for WAP and SMS apps
Bruce Scharlau, University of Aberdeen, 2010
Some examples are online
• Developers Home provides details about
SMS and low level tutorial
http://www.developershome.com/sms/
• O’Reilly have Java tutorial too
http://tim.oreilly.com/pub/a/onjava/2004/06/09/sms.html?page=1
• http://www.esendex.co.uk/ provide API to run
SMS apps – free developer period
Bruce Scharlau, University of Aberdeen, 2010
Txteagle outsources work to
everyone
• Break work into useful chunks anyone can
do via text
• SMS surveys with airtime compensation
• Train workers so know reliability
http://txteagle.com/
Bruce Scharlau, University of Aberdeen, 2010
Deconstruct tasks for greater
speed and security
http://txteagle.com/?q=technology
Bruce Scharlau, University of Aberdeen, 2010
Txteagle changes lives
http://www.youtube.com/watch?v=dBsLAecq6Jw -short version – 6 minutes
http://www.youtube.com/watch?v=Ivz2foChQYU -long version – 40 minutes
http://txteagle.com/?q=workforce/geographies
Bruce Scharlau, University of Aberdeen, 2010