Reputation: 1889
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!!
Upvotes: 0
Views: 155
Reputation: 2186
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);
Upvotes: 0
Reputation: 12717
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);
Upvotes: 1