To handle the aftermath, additional functions are coded for onPaymentCancelled(), onPaymentFailed(); and onPaymentSucceeded(). onActivityResult() is added to handle when the activity has been terminated.
This approach requires a network connection to be active at the time of payment. Hence the permission for PHONE_STATUS
CAUTION: PayPal has its async thread run even if an app's user never makes a purchase, or does so infrequently. In other words, PayPal asks that their thread be started during onCreate() when your app starts, which results in memory being consumed regardless of payments being made.
A better architecture would be for an intermediate app to start-up the PayPal service only (and consume memory) only when a user makes a payment. This would, however, cause a slight delay not present if the PayPal service is already waiting.
The PayPal secondary activity could optionally store payment requests which can be completed automatically when a network becomes available.
Another micro-blogging example is at https://github.com/pilhuhn/ZwitscherA, which goes to Twitter.
Methods to control a service's lifetimes is defined in an app's manifest file.
There are (as of this writing) 122 permissions listed in the Android Reference
READ_PHONE_STATE permissions are needed for
INTERNET permissions are needed for
Instead of AlarmManager.set for specific time, use AlarmManager.setInexactRepeating, which combines several timers.
Launch intents from an app, to return a value.
Name | Intent | App | Returns |
---|---|---|---|
Calculator | org.openintents.action.CALCULATOR | RpnCalc (Reverse Polish Notation) by Edward Falk | final X value |
Plot pie chart | com.googlecode.chartdroid.intent.action.PLOT | chartdroid | - |
Pick Bluetooth device | PICK_BLUETOOTH_DEVICE | - | MAC Address and Name |
Barcode Encode | com.google.zxing.client.android.ENCODE | zxing | barcode display on screen |
Barcode Scan | com.google.zxing.client.android.SCAN | zxing | barcode display on screen |
Flashlight | com.teslacoilsw.intent.FLASHLIGHT | TeslaLED Flashlight by TeslaCoil Software | turn on camera flash LED |
Show a flickr photo | com.google.android.photostream.FLICKR_PHOTO | Flickr.com | - |
Show a flickr stream | com.google.android.photostream.FLICKR_STREAM | Flickr.com | - |
Pronounce Text | ? | Say So | sound |
Search | android.intent.action.SEARCH
android.intent.action.WEB_SEARCH | - | - |
Translate | org.openintents.action.TRANSLATE | - | Translated text |
Historify | org.openintents.historify.permission.USE_BRIDGE | - | aggregated contact-related events gathered from various sources |
Vibrate | com. motiv.action.VIBRATE | - | (nothing) |
Java Base Class: ContentProvider store, query, and retrieve data (such as open a phone contact) across apps.
WEBSITE: Tutorial on this (and other Android topics) on Sai Geetha's excellent blog.
REMINDER: Android services cannot directly handle events such as SMS and system messages.
REMINDER: Unlike .NET and C# which have event listeners and delegates, Android developers need to create a subscribe and publish mechanism (following a observer design pattern).
First, register for broadcast intents.
Broardcast receivers are woken up when an intent for it arrives.
To receive system messages (such as trigger an alarm upon an event), specify a <receiver manifest tag for a class which inherits the BroadcastReceiver class to override onReceive() which then calls startService().
Building push applications for Android by Debajit Ghosh introduces Google's Android C2DM (Cloud to Device Messaging Framework), showing you how you can integrate mobile alert, send-to-phone, and two-way push sync functionality into Android apps.
C2DM was added by Android 2.2. http://gwt-dev-plugin-missing.appspot.com/ GWT Browser Plugin / Google Web Toolkit install instructions
GPE: Google Plugin for Eclipse • GAE: Google App Engine for Java
Google App Engine supports Java Data Objects (JDO) and Java Persistence API (JPA) interfaces to store data in a Master/Slave and High Replication Datastores.
LIB: Deacon is an open-source library that takes advantage of "cloud to device (push) messaging" since Android 2.2 from your server rather than a commercial service.
LIB: Mobile Push API push content directly to phones using SMS and HTTP. This avoid the need to frequently poll for updates.
Examples of remote services are ...
The app can connect to another service (and start it if it's not already running) by invoking a Context.bindService() method through an interface exposed by the service.
A requirement (even though it's not used for started services) is to override onBind(Intent intent) which always return null. This uses the Binder IPC (Inter-process communication "object-oriented" driver originally from BeOS,.acquired by Palm). which provides thread pooling and asynchronous execution of services defined via AIDL.
These remote service run in a different device process than the client service communicating with it. Each client connecting to the process would have its own thread.
So a client Java program must first connect to the service by invoking an onBind() method, which returns a stub class object back to the client. That's myRemoteServiceStub in the sample code below.
public IBinder onBind(Intent arg0) { Log.d(getClass().getSimpleName(), "onBind()"); return myRemoteServiceStub; }
The service has to declare a service interface in an aidl file
The AIDL (Android Interface Definition Language) tool in the Android Eclipse SDK automatically creates a java interface corresponding to the aidl file.
The AIDL tool also generates a stub class that provides an abstract implementation of the service interface methods. The actual service class will have to extend this stub class to provide the real implementation of the methods exposed through the interface.
Communication between processes then occur using a serial (sequential) communication mechanism. So java objects in memory must be serialized (aka marshalled [wikipedia]).
The AIDL file is in folder where java is stored.
package com.company.system.package; interface IMyRemoteService { int getCounter(); void log_d(String tag, String message); void log(in Message msg); }
Once you write this AIDL file (.aidl) in eclipse, it will automatically generate the Remote interface corresponding to this file. The remote interface will also provide a stub inner class which has to have an implementation provided by the RemoteService class. The stub class implementation within the service class is as given here:
private IMyRemoteService.Stub myRemoteServiceStub = new IMyRemoteService.Stub() { public int getCounter() throws RemoteException { return counter; } };
In the web services world, REpresentational State Transfer (REST) is a key design idiom (described in Roy Fielding's PhD Thesis) that embraces a stateless client-server architecture in which web services are viewed as resources identified by their URLs. Web service clients that want these resources access a particular representation by transferring application content using a small globally defined set of remote methods that describe the action to be performed on the resource. REST is an analytical description of the existing web architecture, and thus the interplay between the style and the underlying HTTP protocol appears seamless.
LIB: App Engine Rest Client for Android (AERC) [GIT] written by Google's Tim Bray is an App Engine Connected Android Project.
LIB: JSON/RPC
LIB: RSS reader
LIB: android-xmlrpc is a very thin yet complete xmlrpc client side library.
BOOK:
Pro Android Web Apps:
Developing HTML5, JavaScript, CSS,
and Chrome OS Web Apps
by Damon Oehlman:
reviews these web standards
as they apply to Android.
Android's LibWebCore is based on the Apple Safari browser, which uses the open-source WebKit library to render HTML with CSS, AJAX, etc.
http://en.wikipedia.org/wiki/Android_(operating_system)
To create an intent to open a web browser to a specific URI:
new Intent(android.content.Intent.VIEW_ACTION ,ContentURI.create("http://anddev.org"));
Query the default engine (Google) to make a text search:
Intent searchGivenText = new Intent(Intent.ACTION_WEB_SEARCH);
searchGivenText.putExtra(SearchManager.QUERY, "Android Examples");
startActivity(searchGivenText);
LIB: $199/250 installs iprintsdk add printing to printers on the local network , Wifi printer, Bluetooth printer.
LIB: Jackson markshalls/unmarshals JSON
APP: HP ePrint Home & Biz takes an URI of the image to be printed (with MIME type "image/*") and prints it on a nearby HP ePrint wireless printer. It's sneaky in that it not just not support older iPrint for older HP printers, but deletes prior version that does: HP iPrint Photo programmed using the Print Image OpenIntent.
To call phone number 8005551212:
Intent callNumber = new Intent(); callNumber.setAction(android.content.Intent.ACTION_CALL); callNumber.setData(Uri.parse("tel:8005551212")); startActivity(callNumber);
LIB: $199/250 installs iprintsdk add printing to printers on the local network , Wifi printer, Bluetooth printer.
LIB: Jackson markshalls/unmarshals JSON
APP: HP ePrint Home & Biz takes an URI of the image to be printed (with MIME type "image/*") and prints it on a nearby HP ePrint wireless printer. It's sneaky in that it not just not support older iPrint for older HP printers, but deletes prior version that does: HP iPrint Photo programmed using the Print Image OpenIntent.
TIP: To avoid blocking (system waiting) until a new line is received, use in.ready() to check if a new line is available before calling in.readline().
Location API and Google Maps in Android - Tutorial by Lars Vogel
LIB: $200 xtify enables location based push notification managed through their backend.
To send a waypoint (fix) from a fake GPS device to the Android Emulator, Run a Command session and invoke a telnet client to connect to the Emulator on localhost port 5554, then send a latitude and longitude fix:
LIB: CWAC Location Poller: Finding Your Location Periodically
Intent to Show GPS Status
com.eclipsim.gpsstatus.VIEW
Shows the status of the GPS receiver, including the signal strength and location of visible satellites.
Google Maps require a constant Internet connection and use proprietary resources.
LIB: $200 mAppWidget builds off-line map apps with tools for splicing images and services to display them with zooming.
LIB: $200 Mobile Maps enables access to the map data from either TeleAtlas or OpenStreetMap.
GPX (GPS eXchange Format) shown in DDMS
KML (Keyhole Markup Language) for expressing geographic annotation and visualization
To use Google Maps to show a map to a specific location (Bangalore):
Intent searchAddress = new Intent(Intent.ACTION_VIEW ,Uri.parse("geo:0,0?q=Bangalore")); startActivity(searchAddress);
LIB: OpenSocial Java Client works with OpenSocial data on your server.
LIB: SocialLib provides access to several social networks : Facebook, Twitter, Google Buzz, LinkedIn.
LIB: fbconnect to join the collective.
Facebook.com guides developers on using their login at http://developers.facebook.com/docs/guides/mobile/
Social media icons from:
http://paulrobertlloyd.com/2009/06/social_media_icons, which is adapted from:
http://www.komodomedia.com/blog/2009/06/social-network-icon-pack/
To view contacts on the phone:
Intent contacts = new Intent(); contacts.setAction(android.content.Intent.ACTION_VIEW); contacts.setData(People.CONTENT_URI); startActivity(contacts);OAuth
Meetup.com opened information on their site via an OAuth API, by Doug Tangren since May 2011
LIB: Brion-Learns-OAuth is the result of Brion N. Emde's work to connect his demo app with Twitter using the OAuth SignPost library.
LIB: SignPost for Android to make OAuth calls.
LIB: OAuth for Android a proof-of-concept using Content Providers to store OAuth data.
In How to create a Twitter client (in 4 parts)
JTwitter library provides access to the Twitter API. Download it with fixes by Markakana.
OAuth requires code signing on the client-side using signpost-core and signpost-commonshttp4 jars for signing OAUTH requests.
Intercept Force.com Workflow Outblound SOAP messages in a Ruby server every time object Y has its field X set to Z then perform action Q.
Send to SNMP traps.
NFC (Near Field Communications) standard set by nfc-forum.org, which licenses use of the N-Mark designating use of a very short range RF wireless comm at 13.56 Mhz, with a range of 4cm and data transfer of 106-848 kbits/s.
Peer-to-peer mode enables devices to communicate with each other via NFC.
LIB: Open NFC is an open source stack implementing the NFC functionalities, SDK add-on to enable RFID communication on Android.
SAMPLE APP: AndroidBeamDemo in the Android SDK
Visa & American Express POS readers accept contact-less cards (such as those used on BART and at Starbucks) like RFID tags are passive, with the RF field powered by the initiator. Google Wallet enables one-tap payment
A mobile phone can make payments through mTech software, a TSP (Trusted Service Provider) Issuer server, or a TSM (Trusted Service Manager) control server (made by Vivotech).
FaceCash shows face picture of registered phone owner face for security verification (rather than paper or plastic). Both purchaser and retailer must have accounts.