Service Implementation

In this section we will cover the details up designing and implementing the background services of the application. The background service will be running ONLY while an active trip is in progress, and will handle the following:

- Logging of Text Messages (inbound/outbound) to the trip.
- Logging of Pictures
- Logging of Calls (inbound/outbound)
- Periodically show the Mood-reading dialog at an interval specified in the application settings.
- Register for location changes and do necessary logic upon change.

Logging of Text Messages (inbound/outbound)

Incoming text messages can be received through the intent android.intent.action.DATA_SMS_RECEIVED. A Broadcastreceiver is registered programmatically (as opposed to registration in the manifest) to handle the intent. The receiver spawns a new thread, in which it calls the TripRepository? to save the SMS to the current trip.

Outgoing text messages are a bit more complex. No intent is fired upon sent message, so we need to register a listener to the sms/sent or sms/outbox directory through the content resolver. See below code:

private class SMSObserver extends ContentObserver {

		public SMSObserver(Handler handler) {
			super(handler);
		}

		@Override
		public void onChange(boolean selfChange) {
			// TODO Auto-generated method stub
			super.onChange(selfChange);
			Uri uriSMSURI = Uri.parse("content://sms/outbox"); //maybe it should be sms/sent?
			Cursor cur = getContentResolver().query(uriSMSURI, null, null,
					null, null);
			cur.moveToNext();
			String protocol = cur.getString(cur.getColumnIndex("protocol"));
			if (protocol == null)    //if !null then incoming
				System.out.println("SMS afsendt!");
		}
	}

Currently there is a problem with this method, since the it is called twice upon sending a message. What could be the cause? Therefore: Not yet implemented.