0

I got a class that calculates my location and print it on the screen. Now I want to send a sms every x time with that adress to a certain number. So that requires the sleep method I guess which means I need a class that extends Thread .. but how that class would take the TextView string from the other one? how they will be connected to each other? btw I found this code somewhere in this forum for sending a sms:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"+ phoneNumber)));

Thanks in advanced!!

Imri Persiado
  • 1,857
  • 8
  • 29
  • 45

2 Answers2

1

you can use SmsManager,

 String Text = "My location is: " +
    "Latitude = " + current_lat +
    "Longitude = " + current_lng;

    SmsManager sender=SmsManager.getDefault();
    sender.sendTextMessage("9762281814",null,Text , null, null);
Talha
  • 12,673
  • 5
  • 49
  • 68
  • Thats a nice way to send a sms but I need to send a sms every x time which means it has to be done through a thread. – Imri Persiado Nov 25 '12 at 17:51
  • Ok I done it by sending the class reference to the other class the sends the sms and then it can gets the TextView text. thanks. – Imri Persiado Nov 25 '12 at 18:05
0

Wrap your Thread related stuff in an Async task, and pass it a Context parameter of the current activity. This way you could call the Context.findViewById() inside the doInBackGround() method of the async task. This way you'd not even be performing any blocking action on the main thread (which would lead you to another exception in the future).

public void SendSmsTask extends AsyncTask<Context, Void, Void> {
  @Override
  protected Void doInBackGround(Context... contexts) {
    for(Context con : contexts) {
      TextView abc = context.findViewById(<textview Id>);
      // send your sms after this
    }
  }
... // remaining functions and logic
}

You can start this task from your activity using:

new SendSmsTask().execute(this);
varevarao
  • 2,186
  • 13
  • 26