Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6583745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:26:57+00:00 2026-05-25T16:26:57+00:00

Following are the classes that i’m trying to implement, but i dont know where

  • 0

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.

SERVICE CLASS

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 && 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;
        }

    }

RECEIVER CLASS

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 < 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);
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:26:58+00:00Added an answer on May 25, 2026 at 4:26 pm

    Your answer is probably there :

    http://developer.android.com/guide/topics/fundamentals/services.html

    Citations from the webpage :


    Caution:

    A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process (unless you specify otherwise). This means that, if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work. By using a separate thread, you will reduce the risk of Application Not Responding (ANR) errors and the application’s main thread can remain dedicated to user interaction with your activities.


    Should you use a service or a thread?

    A service is simply a component that can run in the background even when the user is not interacting with your application. Thus, you should create a service only if that is what you need.

    If you need to perform work outside your main thread, but only while the user is interacting with your application, then you should probably instead create a new thread and not a service. For example, if you want to play some music, but only while your activity is running, you might create a thread in onCreate(), start running it in onStart(), then stop it in onStop(). Also consider using AsyncTask or HandlerThread, instead of the traditional Thread class. See the Processes and Threading document for more information about threads.

    Remember that if you do use a service, it still runs in your application’s main thread by default, so you should still create a new thread within the service if it performs intensive or blocking operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following issue. I have two classes that manipulate information but they
I have an the following scenario: // several classes that implement different interfaces class
I have an hierarchy of classes that looks like the following: class Critical {
I'm looking at some Java classes that have the following form: public abstract class
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
as weSuppose that I am creating a Java project with the following classes com.bharani.ClassOne
I have the following classes: Defect - represents a type of data that can
If you have the following: Asp.Net MVC 2 project having object classes that define
I have two tables (tbArea, tbPost) that relate to the following classes. class Area
I have classes like the following. That is many classes with the same few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.