03/10: refs #999 Answer to a sms : reask saying the action if the user says nothing understandable
This is an automated email from the git hooks/post-receive script. New commit to branch devel in repository say-my-texts. See http://git.chorem.org/say-my-texts.git commit 4aadb7611b3fae4c6f64255b5e2f35b1b1702f07 Author: Kevin Morin <morin@codelutin.com> Date: Wed Apr 16 07:41:48 2014 +0000 refs #999 Answer to a sms : reask saying the action if the user says nothing understandable --- pom.xml | 8 +- res/values-fr/strings.xml | 2 + res/values/strings.xml | 1 + .../android/saymytexts/SayMyTextService.java | 259 +++++++++++++-------- .../saymytexts/SayNextActionBroadcastReceiver.java | 30 ++- 5 files changed, 196 insertions(+), 104 deletions(-) diff --git a/pom.xml b/pom.xml index 2bda178..b6ed9c4 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom4redmine</artifactId> - <version>5.0.1</version> + <version>5.0.5</version> </parent> <groupId>org.chorem.android</groupId> @@ -153,6 +153,12 @@ </dependency> <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>${guavaVersion}</version> + </dependency> + + <dependency> <groupId>ch.acra</groupId> <artifactId>acra</artifactId> <version>4.5.0</version> diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml index b652157..6251e8e 100644 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@ -39,4 +39,6 @@ <string name="modifiy_action">corriger</string> <string name="cancel_action">annuler</string> + <string name="voice_not_recognized">Je n\'ai pas compris.</string> + </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 182790a..f77751d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -39,5 +39,6 @@ <string name="confirm_action">confirm</string> <string name="modifiy_action">modify</string> <string name="cancel_action">cancel</string> + <string name="voice_not_recognized">I did not understand.</string> </resources> diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java index c137d98..6056a0f 100644 --- a/src/org/chorem/android/saymytexts/SayMyTextService.java +++ b/src/org/chorem/android/saymytexts/SayMyTextService.java @@ -26,6 +26,7 @@ package org.chorem.android.saymytexts; import android.app.Service; import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothHeadset; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -39,9 +40,9 @@ import android.speech.tts.UtteranceProgressListener; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; +import com.google.common.base.Function; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -60,6 +61,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList public static final String ACTION_READ_SMS = "org.chorem.android.saymytexts.READ_SMS"; public static final String ACTION_READ_NEXT_SMS = "org.chorem.android.saymytexts.READ_NEXT_SMS"; public static final String ACTION_MANAGE_BT_DEVICE = "org.chorem.android.saymytexts.ADD_BT_DEVICE"; + public static final String ACTION_REASK_ACTION = "org.chorem.android.saymytexts.REASK_ACTION"; public static final String ACTION_DICTATE_SMS = "org.chorem.android.saymytexts.DICTATE_SMS"; public static final String ACTION_CONFIRM_SMS_SENDING = "org.chorem.android.saymytexts.CONFIRM_SMS_SENDING"; @@ -71,6 +73,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList public static final String INTENT_EXTRA_ADD_BT_DEVICE = "addBtDevice"; /** Bluetooth device which has just connected or disconnected */ public static final String INTENT_EXTRA_DICTATED_MESSAGE = "dictatedMessage"; + /** Attempt number: if set, it means that the user said something not understandable, so ask again */ + public static final String INTENT_EXTRA_ATTEMPT_NUMBER = "attemptNumber"; /** utterance id when the bluetooth device is connected */ protected static final String BT_UTTERANCE_ID = "btUtteranceId"; @@ -104,6 +108,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList } }; + BluetoothHeadset mBluetoothHeadset; + @Override public void onCreate() { super.onCreate(); @@ -120,6 +126,34 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList intentFilter = new IntentFilter(DictateSmsBroadcastReceiver.ACTION_DICTATE_SMS); registerReceiver(new DictateSmsBroadcastReceiver(), intentFilter); + +//// Get the default adapter +// final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); +// +//// Define Service Listener of BluetoothProfile +// BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() { +// public void onServiceConnected(int profile, BluetoothProfile proxy) { +// if (profile == BluetoothProfile.HEADSET) { +// mBluetoothHeadset = (BluetoothHeadset) proxy; +// List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices(); +// for ( final BluetoothDevice dev : devices ) { +// if (mBluetoothHeadset.isAudioConnected(dev)) { +// bluetoothDevices.put(dev, dev.getBluetoothClass().getDeviceClass()); +// } +// } +// mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset); +// } +// } +// public void onServiceDisconnected(int profile) { +// if (profile == BluetoothProfile.HEADSET) { +// mBluetoothHeadset = null; +// } +// } +// }; +// +//// Establish connection to the proxy. +// mBluetoothAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile.HEADSET); + } @Override @@ -148,6 +182,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList Log.d(TAG, "action " + action); final SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS); + int attemptNumber = intent.getIntExtra(INTENT_EXTRA_ATTEMPT_NUMBER, 0); + switch (action) { case ACTION_MANAGE_BT_DEVICE: BluetoothDevice device = intent.getParcelableExtra(INTENT_EXTRA_BT_DEVICE); @@ -163,46 +199,47 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList } break; + case ACTION_REASK_ACTION: + askForActionAfterReading(sms, !bluetoothDevices.isEmpty(), ++attemptNumber); + break; + case ACTION_DICTATE_SMS: - if (!bluetoothDevices.isEmpty()) { - registerReceiver(new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE); - if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { - context.unregisterReceiver(this); - dictateSMS(sms); - } - } - }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)); - audioManager.setMode(AudioManager.MODE_IN_CALL); - audioManager.startBluetoothSco(); - - } else { - dictateSMS(sms); + if (attemptNumber > 0) { + } +// if (bluetoothDevices.isEmpty()) { + dictateSMS(sms, attemptNumber + 1); +// } else { +// requestBluetoothSpeakingActivation(new Function<Void, Void>() { +// @Override +// public Void apply(Void input) { +// dictateSMS(sms); +// return null; +// } +// }); +// } break; case ACTION_CONFIRM_SMS_SENDING: // if a message has just been dictated final String dictatedMessage = intent.getStringExtra(INTENT_EXTRA_DICTATED_MESSAGE); - if (!bluetoothDevices.isEmpty()) { - registerReceiver(new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE); - if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { - context.unregisterReceiver(this); - askSendingConfirmation(dictatedMessage, sms); - } - } - }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)); - audioManager.setMode(AudioManager.MODE_IN_CALL); - audioManager.startBluetoothSco(); - - } else { - askSendingConfirmation(dictatedMessage, sms); - } +// if (!bluetoothDevices.isEmpty()) { +// registerReceiver(new BroadcastReceiver() { +// @Override +// public void onReceive(Context context, Intent intent) { +// int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE); +// if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { +// context.unregisterReceiver(this); +// askSendingConfirmation(dictatedMessage, sms); +// } +// } +// }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)); +// audioManager.setMode(AudioManager.MODE_IN_CALL); +// audioManager.startBluetoothSco(); +// +// } else { + askSendingConfirmation(dictatedMessage, sms, ++attemptNumber); +// } break; case ACTION_READ_NEXT_SMS: @@ -248,9 +285,15 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList */ protected void setCanSpeak(Boolean canSpeak) { this.canSpeak = canSpeak; - if (Boolean.TRUE.equals(canSpeak) && !awaitingTexts.isEmpty()) { - SMS sms = awaitingTexts.remove(0); - requestReading(sms); + if (Boolean.TRUE.equals(canSpeak)) { + if (!awaitingTexts.isEmpty()) { + SMS sms = awaitingTexts.remove(0); + requestReading(sms); + + } else if (!bluetoothDevices.isEmpty()) { + audioManager.stopBluetoothSco(); + audioManager.setMode(AudioManager.MODE_NORMAL); + } } } @@ -258,26 +301,32 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList * Requests the reading of one text through the wired headset or bluetooth device * @param sms the text to read */ - protected void requestReading(SMS sms) { + protected void requestReading(final SMS sms) { if (bluetoothDevices.isEmpty()) { readText(sms, false); } else { - requestReadingOverBt(sms); + requestBluetoothSpeakingActivation(new Function<Void, Void>() { + @Override + public Void apply(Void input) { + readText(sms, true); + return null; + } + }); } } /** * Starts the connection with the bluetooth device and requests the reading - * @param sms the texts to read + * @param callback the function called when the bluetooth is ready */ - protected void requestReadingOverBt(final SMS sms) { + protected void requestBluetoothSpeakingActivation(final Function<Void, Void> callback) { registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE); if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { context.unregisterReceiver(this); - readText(sms, true); + callback.apply(null); } } }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)); @@ -300,7 +349,36 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList // waiting = true; - // init texttospeech + HashMap<String, String> params = new HashMap<>(); + params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL)); +// if (btConnected) { +// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID); +// } + + if (heisendroidModeEnabled) { + textToSpeech.setLanguage(Locale.US); + textToSpeech.setSpeechRate(0.3f); + textToSpeech.setPitch(0.1f); + textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params); + } + + textToSpeech.setLanguage(Locale.getDefault()); + textToSpeech.setSpeechRate(1f); + textToSpeech.setPitch(1f); + String text = getString(R.string.sms_received, sms.getSenderName(), sms.getMessage()); + textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params); + + if (heisendroidModeEnabled) { + textToSpeech.setLanguage(Locale.US); + textToSpeech.setSpeechRate(0.3f); + textToSpeech.setPitch(0.1f); + textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params); + } + + askForActionAfterReading(sms, btConnected, 1); + } + + protected void askForActionAfterReading(final SMS sms, boolean btConnected, final int attemptNumber) { textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onStart(String utteranceId) { @@ -313,17 +391,19 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList @Override public void onDone(String utteranceId) { - if (BT_UTTERANCE_ID.equals(utteranceId) || - BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) { - // when the text has been read by the bluetooth device, stop the connection - audioManager.stopBluetoothSco(); - audioManager.setMode(AudioManager.MODE_NORMAL); - } +// if (BT_UTTERANCE_ID.equals(utteranceId)) { +// // when the text has been read by the bluetooth device, stop the connection +// audioManager.stopBluetoothSco(); +// audioManager.setMode(AudioManager.MODE_NORMAL); +// } if (ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId) || BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) { Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION); - sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_SMS, sms); + sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_SMS, sms); + sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_ATTEMPT_NUMBER, attemptNumber); + sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_FALLBACK_ACTION, ACTION_REASK_ACTION); + sendBroadcast(sayaction); } } @@ -331,39 +411,27 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList HashMap<String, String> params = new HashMap<>(); params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL)); - if (btConnected) { - params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID); - } - - if (heisendroidModeEnabled) { - textToSpeech.setLanguage(Locale.US); - textToSpeech.setSpeechRate(0.3f); - textToSpeech.setPitch(0.1f); - textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params); - } textToSpeech.setLanguage(Locale.getDefault()); textToSpeech.setSpeechRate(1f); textToSpeech.setPitch(1f); - String text = getString(R.string.sms_received, sms.getSenderName(), sms.getMessage()); - textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params); - if (heisendroidModeEnabled) { - textToSpeech.setLanguage(Locale.US); - textToSpeech.setSpeechRate(0.3f); - textToSpeech.setPitch(0.1f); - textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params); + if (attemptNumber > 1) { + textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params); } - params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, - btConnected ? BT_ASK_NEXT_ACTION_UTTERANCE_ID : ASK_NEXT_ACTION_UTTERANCE_ID); - textToSpeech.setLanguage(Locale.getDefault()); - textToSpeech.setSpeechRate(1f); - textToSpeech.setPitch(1f); - textToSpeech.speak(getString(R.string.ask_next_action), TextToSpeech.QUEUE_ADD, params); + //TODO add a counter to ask only twice (or 3 times, or it should be configurable) + if (attemptNumber <= 3) { + params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, + btConnected ? BT_ASK_NEXT_ACTION_UTTERANCE_ID : ASK_NEXT_ACTION_UTTERANCE_ID); + textToSpeech.speak(getString(R.string.ask_next_action), TextToSpeech.QUEUE_ADD, params); + + } else { + setCanSpeak(true); + } } - protected void dictateSMS(final SMS sms) { + protected void dictateSMS(final SMS sms, final int attemptNumber) { Log.d(TAG, "dictateSMS " ); textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override @@ -377,14 +445,9 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList @Override public void onDone(String utteranceId) { - if (BT_UTTERANCE_ID.equals(utteranceId)) { - // when the text has been read by the bluetooth device, stop the connection - audioManager.stopBluetoothSco(); - audioManager.setMode(AudioManager.MODE_NORMAL); - } - Intent dictateAction = new Intent(DictateSmsBroadcastReceiver.ACTION_DICTATE_SMS); dictateAction.putExtra(DictateSmsBroadcastReceiver.EXTRA_SMS, sms); +// dictateAction.putExtra(DictateSmsBroadcastReceiver.INTENT_EXTRA_SMS, attemptNumber); sendBroadcast(dictateAction); } @@ -392,8 +455,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList HashMap<String, String> params = new HashMap<>(); params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL)); - params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, - bluetoothDevices.isEmpty() ? BT_UTTERANCE_ID : OTHER_UTTERANCE_ID); + params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID); textToSpeech.setLanguage(Locale.getDefault()); textToSpeech.setSpeechRate(1f); @@ -402,7 +464,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList textToSpeech.speak("dictez votre sms", TextToSpeech.QUEUE_ADD, params); } - protected void askSendingConfirmation(final String message, final SMS originSms) { + protected void askSendingConfirmation(final String message, final SMS originSms, final int attemptNumber) { Log.d(TAG, "askSendingConfirmation " + message); textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override @@ -416,15 +478,11 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList @Override public void onDone(String utteranceId) { - if (BT_UTTERANCE_ID.equals(utteranceId)) { - // when the text has been read by the bluetooth device, stop the connection - audioManager.stopBluetoothSco(); - audioManager.setMode(AudioManager.MODE_NORMAL); - } - Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION); - sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_SMS, originSms); - sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_MESSAGE, message); + sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_SMS, originSms); + sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_MESSAGE, message); + sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_ATTEMPT_NUMBER, attemptNumber); + sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_FALLBACK_ACTION, ACTION_CONFIRM_SMS_SENDING); sendBroadcast(sayaction); } @@ -432,14 +490,25 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList HashMap<String, String> params = new HashMap<>(); params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL)); - params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, - bluetoothDevices.isEmpty() ? BT_UTTERANCE_ID : OTHER_UTTERANCE_ID); textToSpeech.setLanguage(Locale.getDefault()); textToSpeech.setSpeechRate(1f); textToSpeech.setPitch(1f); - String text = getString(R.string.send_sms_confirmation, message); - textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params); + + if (attemptNumber > 1) { + textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params); + } + + //TODO add a counter to ask only twice (or 3 times, or it should be configurable) + if (attemptNumber <= 3) { + params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID); + String text = getString(R.string.send_sms_confirmation, message); + textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params); + + } else { + setCanSpeak(true); + } + } } diff --git a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java index 5689405..4d7bae4 100644 --- a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java +++ b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java @@ -4,7 +4,6 @@ import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.media.AudioManager; import android.media.ToneGenerator; import android.net.Uri; @@ -27,13 +26,15 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver { public static final String ACTION_SAY_NEXT_ACTION = "org.chorem.android.saymytexts.SAY_NEXT_ACTION"; - public static final String EXTRA_SMS = "sms"; - public static final String EXTRA_MESSAGE = "message"; + public static final String INTENT_EXTRA_SMS = "sms"; + public static final String INTENT_EXTRA_MESSAGE = "message"; + public static final String INTENT_EXTRA_ATTEMPT_NUMBER = "attemptNumber"; + public static final String INTENT_EXTRA_FALLBACK_ACTION = "fallbackAction"; @Override public void onReceive(final Context context, final Intent intent) { Log.d(TAG, "next action ?"); - final SMS sms = (SMS) intent.getSerializableExtra(EXTRA_SMS); + final SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS); if (sms != null) { SpeechRecognizer speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context); @@ -66,7 +67,7 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver { //TODO if error 7 ERROR_NO_MATCH ask to say it again //TODO if other error say there is an error tg.startTone(ToneGenerator.TONE_PROP_NACK); - readNext(context); + reaskAction(context, intent, sms); } @Override @@ -99,7 +100,7 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver { context.startService(serviceIntent); } else if (results.contains(context.getString(R.string.confirm_action))) { - String message = intent.getStringExtra(EXTRA_MESSAGE); + String message = intent.getStringExtra(INTENT_EXTRA_MESSAGE); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(sms.getSenderNumber(), null, message, null, null); @@ -116,8 +117,8 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver { readNext(context); } else { - //TODO add a counter to ask only twice (or 3 times, or it should be configurable) - // recognizeVoice(sms); + tg.startTone(ToneGenerator.TONE_PROP_NACK); + reaskAction(context, intent, sms); } } } @@ -138,6 +139,19 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver { } } + protected void reaskAction(Context context, Intent intent, SMS sms) { + int attemptNumber = intent.getIntExtra(INTENT_EXTRA_ATTEMPT_NUMBER, 1); + String fallbackAction = intent.getStringExtra(INTENT_EXTRA_FALLBACK_ACTION); + String dictatedMessage = intent.getStringExtra(INTENT_EXTRA_MESSAGE); + + Intent serviceIntent = new Intent(context, SayMyTextService.class); + serviceIntent.setAction(fallbackAction); + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS, sms); + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_ATTEMPT_NUMBER, attemptNumber); + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_DICTATED_MESSAGE, dictatedMessage); + context.startService(serviceIntent); + } + protected void readNext(Context context) { Intent serviceIntent = new Intent(context, SayMyTextService.class); serviceIntent.setAction(SayMyTextService.ACTION_READ_NEXT_SMS); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm