0

我有一个课程可以计算我的位置并将其打印在屏幕上。现在我想每隔 x 次向某个号码发送一条带有该地址的短信。所以这需要 sleep 方法,我猜这意味着我需要一个扩展 Thread 的类 .. 但是该类如何从另一个类中获取 TextView 字符串?它们将如何相互连接?顺便说一句,我在这个论坛的某个地方找到了这个代码来发送短信:

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

提前致谢!!

4

2 回答 2

1

你可以使用短信管理器,

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

    SmsManager sender=SmsManager.getDefault();
    sender.sendTextMessage("9762281814",null,Text , null, null);
于 2012-11-25T14:47:38.160 回答
0

将与线程相关的内容包装在异步任务中,并将当前活动的 Context 参数传递给它。这样你就可以调用异步任务的Context.findViewById()内部doInBackGround()方法。这样,您甚至不会在主线程上执行任何阻塞操作(这将导致您将来出现另一个异常)。

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
}

您可以使用以下方法从您的活动开始此任务:

new SendSmsTask().execute(this);
于 2012-11-25T14:48:27.553 回答