package com.example.widgettest;
import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.IBinder;
import android.text.format.Time;
import android.widget.RemoteViews;
import android.widget.Toast;
public class sv extends Service{
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
Time mTime=new Time(); // or Time t=new Time("GMT+8");
mTime.setToNow(); // 取得系统时间。
int year = mTime.year;
int month = mTime.month;
int date = mTime.monthDay;
int hour =mTime.hour; // 0-23
int minute = mTime.minute;
int second =mTime.second;
Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();
AppWidgetManager widget = AppWidgetManager.getInstance(this);
RemoteViews views= new RemoteViews("com.example.widgettest.MyWidget", R.layout.main);
views.setTextViewText(R.id.now, hour+":"+minute+":"+second );
widget.updateAppWidget(widget.getAppWidgetIds(new ComponentName(this, MyWidget.class)), views);
stopService(new Intent(sv.this,sv.class));
}
}
沒有留言:
張貼留言