Upload
bryan-odonnell
View
217
Download
1
Tags:
Embed Size (px)
Citation preview
Bruce Scharlau, University of Aberdeen, 2010
Android Storage & SMS Apps
Mobile Computing
Unless otherwise stated, images are from android sdk
See Unlocking Android (Ch 5) for more details
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
Bruce Scharlau, University of Aberdeen, 2010
These are not sharable across applications, unless you expose them as a ‘content provider’.
We can write larger data to file
• You can either write to a new file, or to a pre-included 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
You can only access files available to the application
File writing is similar to what you’ve done before
Bruce Scharlau, University of Aberdeen, 2010
Source: unlocking android, p 159
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.
Bruce Scharlau, University of Aberdeen, 2010
Can save files automatically, or at user discretion with time values, etc. (twitter, email apps, or photo capture)
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
Bruce Scharlau, University of Aberdeen, 2010
Useful db helper class for access and crud details
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
Bruce Scharlau, University of Aberdeen, 2010
Stores locations to database within application as objects
Unlocking Android app uses db helper classes with sql
Bruce Scharlau, University of Aberdeen, 2010
public static class Location {
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() { }
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; this.region = region; }
Source: unlocking android, code
Part of DBHelper class showingLocation object
Class also holds crud details to map object to sql
Unlocking Android app maps objects to sql for ease
Bruce Scharlau, University of Aberdeen, 2010
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); }
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); values.put("lastalert", location.lastalert); values.put("alertenabled", location.alertenabled); this.db.update(DBHelper.DB_TABLE, values, "_id=" + location.id, null); }
Source: unlocking android, code
Mapping makes coding easier
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
Enables off network use and can sync later when connected
Bruce Scharlau, University of Aberdeen, 2010
Might be pushing limits of device though with extra classes and memory usage
Can read items from network as xml and convert to objects, which map to db
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
Bruce Scharlau, University of Aberdeen, 2010
Available to all handsets for wider usage
Faster to market for specific events
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
Bruce Scharlau, University of Aberdeen, 2010
http://www.textsmsmarketing.com/sms-text-marketing-case-studies.php
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
Bruce Scharlau, University of Aberdeen, 2010
http://www.spotlightideas.co.uk/?p=4582
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
Bruce Scharlau, University of Aberdeen, 2010
http://www.developershome.com/sms/
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
Bruce Scharlau, University of Aberdeen, 2010http://txteagle.com/
Deconstruct tasks for greater speed and security
Bruce Scharlau, University of Aberdeen, 2010http://txteagle.com/?q=technology
Txteagle changes lives
Bruce Scharlau, University of Aberdeen, 2010
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