14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9: Peer-to-Peer Communication<br />

306<br />

13.4. Finally, register the new Broadcast Receiver by extending the onCreate method of the<br />

Emergency Responder Activity.<br />

@Override<br />

public void onCreate(Bundle icicle) {<br />

super.onCreate(icicle);<br />

setContentView(R.layout.main);<br />

}<br />

lock = new ReentrantLock();<br />

requesters = new ArrayList();<br />

wireUpControls();<br />

IntentFilter filter = new IntentFilter(SMS_RECEIVED);<br />

registerReceiver(emergencyResponseRequestReceiver, filter);<br />

IntentFilter attemptedDeliveryfilter = new IntentFilter(SENT_SMS);<br />

registerReceiver(attemptedDeliveryReceiver, attemptedDeliveryfilter);<br />

You can now run the application. To test it, you need to open two emulator instances with the application<br />

running in one of them.<br />

Use the DDMS emulator controls to mimic sending an “are you safe” message from one emulator to the<br />

other (using its port number as the originating number). When you press one of the response buttons,<br />

you should see a new SMS message appear in the mimicked emulator.<br />

Automating the Emergency Responder<br />

In the following example, you’ll fi ll in the code behind the Set up Auto Responder button added in the<br />

previous example, to let the Emergency Responder automatically respond to status update requests.<br />

1. Start by creating a new autoresponder.xml layout resource that will be used to lay out the automatic<br />

response confi guration window. Include an EditText for entering a status message to<br />

send, a Spinner to choose the auto-response expiry time, and a CheckBox to let users choose if<br />

they want to include their location in the automated responses.<br />

<br />

<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!