Skip to content

Commit eabb611

Browse files
committed
update example and remove unused code
1 parent 384e9a6 commit eabb611

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

app/src/main/java/helper/update/widget/com/widgetupdatehelper/UpdateService.java

-19
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,6 @@ public void onCreate() {
8888
}
8989
}
9090

91-
/**
92-
* Static method for starting update Widget with AppWidgetProvider.class and ids
93-
*
94-
* @param context context for intent
95-
* @param widgetClass for {@link ComponentName} associated with widget that will
96-
* be updated
97-
* @param dataBundle bundle of data, that you need to build a RemoteViews
98-
* @param widgetId id that will be updated
99-
*/
100-
public static void updateWidgets(Context context,
101-
Class<? extends AppWidgetProvider> widgetClass,
102-
Bundle dataBundle, int widgetId) {
103-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
104-
context.startService(getIntentUpdateWidget(context, widgetClass, dataBundle, widgetId));
105-
} else {
106-
context.startService(getIntentUpdateWidget(context, widgetClass, dataBundle, widgetId));
107-
}
108-
}
109-
11091
@Override
11192
public int onStartCommand(Intent intent, int flags, int startId) {
11293
LogWrapper.d(LOG_TAG, String.format("onStartCommand -> intent=%s, flags=%s, startId=%s",

example/src/main/java/helper/update/widget/com/example/single/SingleRemoteViewBuilder.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ private static PendingIntent getPendingIntent(Context context, String text, Stri
7777
.putExtra(EXTRA_PROVIDER, new ComponentName(context, ExampleSingleAppWidget.class))
7878
.putExtra(EXTRA_WIDGET_IDS, new int[]{widgetId})
7979
.putExtra(EXTRA_DATA_BUNDLE, bundle);
80-
return PendingIntent.getService(context, widgetId, updateServiceIntent,
81-
PendingIntent.FLAG_CANCEL_CURRENT);
80+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
81+
return PendingIntent.getForegroundService(context, widgetId, updateServiceIntent,
82+
PendingIntent.FLAG_CANCEL_CURRENT);
83+
} else {
84+
return PendingIntent.getService(context, widgetId, updateServiceIntent,
85+
PendingIntent.FLAG_CANCEL_CURRENT);
86+
}
8287
}
8388
}

0 commit comments

Comments
 (0)