android修改系统时区
import java.util.Calendar;
import java.util.Timer;
import android.R.integer;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
public class ZoneService extends Service {
private static final String ACTION_DATE_CHANGED = Intent.ACTION_DATE_CHANGED;
private static final String ACTION_TIME_CHANGED = Intent.ACTION_TIME_CHANGED;
private BroadcastReceiver TimerChangered = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Calendar c = Calendar.getInstance();// 可以对每个时间域单独修改
// int year = c.get(Calendar.YEAR);
// int month = c.get(Calendar.MONTH);
// int date = c.get(Calendar.DATE);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
Log.v("time", Integer.toString(hour)+Integer.toString(minute)+Integer.toString(second));
}
};
private BroadcastReceiver stopServiceReceiver = new BroadcastReceiver() {
public void onReceive(android.content.Context context, Intent intent) {
ZoneService.this.stopSelf();
ZoneService.this.unregisterReceiver(stopServiceReceiver);
};
};
@Override
public void onCreate() {
super.onCreate();
Log.i("liujun", "后台进程被创建。。。");
IntentFilter intentFilter = new IntentFilter("closeService");
ZoneService.this.registerReceiver(stopServiceReceiver, intentFilter);
// 服务启动广播接收器,使得广播接收器可以在程序退出后在后天继续执行,接收系统时间变更广播事件
ZoneService.this.registerReceiver(TimerChangered, new IntentFilter(
Intent.ACTION_TIME_TICK));
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("liujun", "后台进程。。。");
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
Log.i("liujun", "后台进程被销毁了。。。");
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
// TODO 自动生成的方法存根
return null;
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。