机器人:定期发送短信 [英] android : send sms periodically
本文介绍了机器人:定期发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须定期通过我的Android应用程序发送短信到某一群人(朋友)发送将被存储在应用程序仅
I have to send sms periodically through my android application to a certain group of people (friends).The messages to be sent will be stored in a database in the application only
我看到以下主题:
推荐答案
使用服务:
import java.util.Timer;
import java.util.TimerTask;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.IBinder;
import android.os.Message;
import android.widget.Toast;
public class SrvSMSSender extends Service {
Timer timerSendSMS = new Timer();
class taskSendSMS extends TimerTask {
@Override
public void run() {
hSendSMS.sendEmptyMessage(0);
}
};
final Handler hSendSMS = new Handler(new Callback() {
@Override
public boolean handleMessage(Message msg) {
procSendSMS();
return false;
}
});
public void procSendSMS() {
try {
// send your SMS here
} catch (Exception e) {
}
}
@Override
public void onCreate() {
super.onCreate();
};
@Override
public void onStart(Intent intent, int startId) {
try {
long intervalSendSMS = 10*60*1000;
timerSendSMS = new Timer();
timerSendSMS.schedule(new taskSendSMS(), 0, intervalSendSMS);
} catch (NumberFormatException e) {
Toast.makeText(this, "error running service: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, "error running service: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onDestroy() {
timerSendSMS.cancel();
timerSendSMS.purge();
}
}
这篇关于机器人:定期发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文