Back to project page BatteryWidget-Android.
The source code is released under:
GNU General Public License
If you think the Android project BatteryWidget-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.batterysimplewidget; import com.batterysimplewidget.R; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.content.Intent; public class BatteryAppWidgetProvider extends AppWidgetProvider { static int currentLayout = R.layout.main; @Override/*from w w w . j ava 2s.c o m*/ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { context.startService(new Intent(context, BatteryService.class)); } @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { this.onDeleted(context, new int[] { appWidgetId }); } } else { super.onReceive(context, intent); } } @Override public void onDeleted(Context context, int[] appWidgetIds) { super.onDeleted(context, appWidgetIds); context.stopService(new Intent(context, BatteryService.class)); } }