forked from kivy/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathService.tmpl.java
More file actions
102 lines (85 loc) · 3.1 KB
/
Copy pathService.tmpl.java
File metadata and controls
102 lines (85 loc) · 3.1 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package {{ args.package }};
import java.io.File;
import android.os.Build;
import android.content.Intent;
import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
import org.kivy.android.PythonService;
import org.kivy.android.PythonServiceIntent;
import org.kivy.android.PythonUtil;
public class Service{{ name|capitalize }} extends PythonService {
private static final String TAG = "PythonService";
{% if sticky %}
@Override
public int startType() {
return START_STICKY;
}
{% endif %}
@Override
protected int getServiceId() {
return {{ service_id }};
}
public static void prepare(Context ctx) {
String appRoot = PythonUtil.getAppRoot(ctx);
Log.v(TAG, "Ready to unpack");
File app_root_file = new File(appRoot);
PythonUtil.unpackAsset(ctx, "private", app_root_file, true);
PythonUtil.unpackPyBundle(ctx, ctx.getApplicationInfo().nativeLibraryDir + "/" + "libpybundle", app_root_file, false);
}
static private void _start(Context ctx, String smallIconName,
String contentTitle,
String contentText,
String pythonServiceArgument) {
Intent intent = getDefaultIntent(ctx, smallIconName, contentTitle,
contentText, pythonServiceArgument);
//foreground: {{foreground}}
{% if foreground %}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ctx.startForegroundService(intent);
} else {
ctx.startService(intent);
}
{% else %}
ctx.startService(intent);
{% endif %}
}
public static void start(Context ctx, String pythonServiceArgument) {
_start(ctx, "", "{{ args.name }}", "{{ name|capitalize }}", pythonServiceArgument);
}
static public void start(Context ctx, String smallIconName,
String contentTitle,
String contentText,
String pythonServiceArgument) {
_start(ctx, smallIconName, contentTitle, contentText, pythonServiceArgument);
}
static public Intent getDefaultIntent(Context ctx, String smallIconName,
String contentTitle,
String contentText,
String pythonServiceArgument) {
String appRoot = PythonUtil.getAppRoot(ctx);
return PythonServiceIntent.buildWithPaths(
ctx,
Service{{ name|capitalize }}.class,
appRoot,
appRoot,
appRoot,
"{{ entrypoint }}",
"{{ name|capitalize }}",
null,
"{{ name }}",
"{{ foreground|lower }}",
pythonServiceArgument,
smallIconName,
contentTitle,
contentText);
}
@Override
protected Intent getThisDefaultIntent(Context ctx, String pythonServiceArgument) {
return Service{{ name|capitalize }}.getDefaultIntent(ctx, "", "", "",
pythonServiceArgument);
}
static public void stop(Context ctx) {
PythonServiceIntent.stop(ctx, Service{{ name|capitalize }}.class);
}
}