Back to project page SMS-Morse.
The source code is released under:
GNU General Public License
If you think the Android project SMS-Morse listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jonathanmackenzie.sms_morse; //ww w . j a v a 2 s. c om import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.telephony.SmsMessage; import android.util.Log; /** * A receiver that listens for incoming SMS messages. * On receive, it will play back the message in Morse code * @author Jonathan Mackenzie * @email jonmac1@gmail.com */ public class SMSMorse extends BroadcastReceiver { private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; @Override public void onReceive(final Context context, Intent intent) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); if(settings.getBoolean("play_on_sms", true)) { if (intent != null && intent.getAction().equals(SMS_RECEIVED)) { final SmsMessage sms = extractSmsMessage(intent); String message = sms.getMessageBody(); if (sms != null && message != null) { Log.i("SMS-Morse", "Received message :" + message); SMSTone tone = new SMSTone(context); String dots = tone.convertToDots(message); tone.play(dots); } } } } /** * Extract SMS from the intent * @param intent * @return the SmsMessage in the intent */ private SmsMessage extractSmsMessage(final Intent intent) { final Bundle pudsBundle = intent.getExtras(); final Object[] pdus = (Object[]) pudsBundle.get("pdus"); final SmsMessage smsMessage = SmsMessage .createFromPdu((byte[]) pdus[0]); return smsMessage; } }