-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathWidgetProvider.java
44 lines (35 loc) · 1.36 KB
/
WidgetProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.androidwidgetpoc;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.facebook.react.HeadlessJsTaskService;
public class WidgetProvider extends AppWidgetProvider {
private static final String WIDGET_TASK = "com.androidwidgetpoc.WIDGET_TASK";
/*
* When enabled on screen, let the BackgroundTaskBridge
* manipulate it from javascript
*/
@Override
public void onEnabled(Context context) {
Log.d("WIDGET_PROVIDER", "En onEnabled");
Intent serviceIntent = new Intent(context, BackgroundTask.class);
context.startService(serviceIntent);
HeadlessJsTaskService.acquireWakeLockNow(context);
}
@Override
public void onReceive(final Context context, final Intent incomingIntent) {
super.onReceive(context, incomingIntent);
if (!incomingIntent.getAction().startsWith("com.androidwidgetpoc.CHARM")) {
return;
}
Intent silentStartIntent = new Intent(context, BackgroundTask.class);
context.startService(silentStartIntent);
/*
* Proxy bundle extras towards the service
* */
Intent serviceIntent = new Intent(context, BackgroundTask.class);
serviceIntent.putExtras(incomingIntent);
context.startService(serviceIntent);
}
}