我为我的应用程序创建了一个小部件以启动。小部件中的数据在30mins
. 我需要将时间减少到2mins
. 我听说可以使用它来完成,AlarmService
但我不知道应该如何实现它。我正在分享我的小部件代码。
public class SampleWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
RemoteViews view;
SampleDatabase linksDatabase = new SampleDatabase(context);
linksDatabase.openDb();
List<MyMedia> myMedias = linksDatabase.getData();
String date = null;
String level = null;
for (int j = 0; j < myMedias.size(); j++) {
date = myMedias.get(j).getDateTime();
level = myMedias.get(j).getLevel();
}
linksDatabase.closeDb();
if (myMedias != null && myMedias.size() > 0) {
for (int i = 0; i < myMedias.size(); i++) {
final int n = appWidgetIds.length;
for (int j = 0; j < n; j++) {
int appWidget = appWidgetIds[j];
Intent intnt = new Intent(context, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 0,
intnt, 0);
view = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
view.setOnClickPendingIntent(R.id.relLayout, pi);
view.setTextViewText(R.id.date, date);
//view.setTextViewText(R.id.time, obtainedTime);
StringBuffer sb = new StringBuffer(level);
sb.append(" ");
sb.append("units");
view.setTextViewText(R.id.value_1, sb.toString());
appWidgetManager.updateAppWidget(appWidget, view);
}
}
}
}
}
任何人都可以帮助我找到实施方法。谢谢