i have the following pgm which responds with a Toast with an incoming msg and also speaks out the received msg, however there seems to be no speech synthesis in background but i still can see the Toast though, so should i start a service from the onReceive method (don't know if that's possible) here and then in the startService method , write the speak method??
here's one of my pgms:
Receiver
package com.example.TextSpeaker;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class Receiver extends BroadcastReceiver{
public static String str;
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Log.d("Receiver","Message received successfully");
SmsMessage[] msgs = null;
if(bundle!=null)
{
// retrive the sms received
Object[] pdus = (Object[])bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0;i<msgs.length;i++)
{
str="";
msgs[i]=SmsMessage.createFromPdu((byte[]) pdus[i]);
str+="Message From "+msgs[i].getOriginatingAddress()+". ";
str+="The message is "+msgs[i].getMessageBody().toString();
//TextSpeaker.mtts.speak(Receiver.str, TextToSpeech.QUEUE_FLUSH,null);
//str="";
}
Toast.makeText(context,str,Toast.LENGTH_LONG).show();
TextSpeaker.mtts.speak(Receiver.str, TextToSpeech.QUEUE_FLUSH,null);
}
}
}