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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

10. To enable the auto-responder, return to the Emergency Responder Activity and update the<br />

startAutoResponder method stub that you created in the previous example. It should open<br />

the AutoResponder Activity you just created.<br />

private void startAutoResponder() {<br />

startActivityForResult(new Intent(EmergencyResponder.this,<br />

AutoResponder.class), 0);<br />

}<br />

11. If you start your project, you should now be able to bring up the Auto Responder settings window<br />

to set the auto-response settings. It should appear as shown in Figure 9-5.<br />

Figure 9-5<br />

12. The fi nal step is to update the requestReceived method in the Emergency Responder Activity<br />

to check if the auto-responder has been enabled.<br />

If it has, the requestReceived method should automatically execute the respond method,<br />

using the message and location settings defi ned in the application’s SharedPreferences.<br />

public void requestReceived(String _from) {<br />

if (!requesters.contains(_from)) {<br />

lock.lock();<br />

requesters.add(_from);<br />

aa.notifyDataSetChanged();<br />

lock.unlock();<br />

// Check for auto-responder<br />

String preferenceName = getString(R.string.user_preferences);<br />

SharedPreferences prefs = getSharedPreferences(preferenceName, 0);<br />

String autoRespondPref = getString(R.string.autoRespondPref)<br />

boolean autoRespond = prefs.getBoolean(autoRespondPref, false);<br />

if (autoRespond) {<br />

String responseTextPref = getString(R.string.responseTextPref);<br />

String includeLocationPref = getString(R.string.includeLocationPref);<br />

String respondText = prefs.getString(responseTextPref, “”);<br />

313

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

Saved successfully!

Ooh no, something went wrong!