Text To Speech not working in service
<p>Following are the classes that i'm trying to implement, but i dont know where should i speak the name that i got from brodcast receiver.Can anyoneone help.</p>

<p><strong>SERVICE CLASS</strong></p>

<pre><code>public class SMSTalk extends Service implements OnInitListener, OnUtteranceCompletedListener {
        public static TextToSpeech mTts;
        private String spokenText;
        public String msg=null;
        int flag=0;

        @Override
        public void onCreate() {
            mTts = new TextToSpeech(this, this);
            // This is a good place to set spokenText
        }
        public void readName(String temp)
        {
            msg=temp;
            System.out.println("HHHHHHHHHHHHHHHHHHH"+msg);
           // mTts.speak(msg, 0, null);

        }

        @Override
        public void onInit(int status) {
            SMSReceiver smsReceiver=new SMSReceiver();
            if (status == TextToSpeech.SUCCESS) {
                int result = mTts.setLanguage(Locale.UK);
                if (result != TextToSpeech.LANG_MISSING_DATA &amp;&amp; result != TextToSpeech.LANG_NOT_SUPPORTED) {
                    System.out.println("@@@@"+msg);
                  Toast.makeText(getApplicationContext(), "SUCCESS",Toast.LENGTH_LONG ).show();
                  mTts.speak("Hello", 0, null);
                  flag=1;

                }
            }
            if(flag==1)
            {
             System.out.println("######"+msg);
             mTts.speak(msg, 0, null);
            }
        }


        @Override
        public void onUtteranceCompleted(String uttId) {
            stopSelf();
            System.out.println("onUtteranceCompleted"+msg);
        }

        @Override
        public void onDestroy() {
            if (mTts != null) {
                mTts.stop();
                mTts.shutdown();
            }
            super.onDestroy();
        }

        @Override
        public IBinder onBind(Intent arg0) {
            return null;
        }

    }
</code></pre>

<p><strong>RECEIVER CLASS</strong></p>

<pre><code>public class SMSReceiver extends BroadcastReceiver
{
     String name=null;
    private Context mContext;


    @Override
    public void onReceive(Context context, Intent intent)
    {   
        // TODO Auto-generated method stub

        int n;
        Bundle bundle = intent.getExtras();
        Object pdus[] = (Object[]) bundle.get("pdus");
        SmsMessage smsMessage[] = new SmsMessage[pdus.length];
        for (n = 0; n &lt; pdus.length; n++)
        {
            smsMessage[n] = SmsMessage.createFromPdu((byte[]) pdus[n]);
        }
        // show first message
        String sms1 = smsMessage[0].getMessageBody();
        String from = smsMessage[0].getOriginatingAddress();
        //String name = getDisplayNameFromPhoneNo( from);
        Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(from));
        Cursor c = context.getContentResolver().query(lookupUri, new String[]{PhoneLookup.DISPLAY_NAME}, null, null, null);
         while(c.moveToNext()){ 
                /* If we find a match we put it in a String.*/ 
               name = c.getString(c.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));  
                 }

        Toast toast = Toast.makeText(context, "SMS Received from: " + from, Toast.LENGTH_LONG);
        toast.show();

        System.out.println("!!!!"+name);
        Toast.makeText(context, "name: " + name, Toast.LENGTH_LONG).show();
        //smsTalk.speakSMS(name);
        //SMSTalk.mTts.speak("You have an SMS from "+name, 0, null);
        context.startService(new Intent(context,SMSTalk.class));
        SMSTalk smsTalk = new SMSTalk();
        smsTalk.readName(name);
    }


}
</code></pre>
