@@ -15,14 +15,42 @@ public class Service{{ name|capitalize }} extends PythonService {
1515
1616 private static final String TAG = "PythonService" ;
1717
18+ {% if sticky %}
19+ @ Override
20+ public int startType () {
21+ return START_STICKY ;
22+ }
23+ {% endif %}
24+
25+ @ Override
26+ protected int getServiceId () {
27+ return {{ service_id }};
28+ }
29+
1830 public static void prepare (Context ctx ) {
1931 String appRoot = PythonUtil .getAppRoot (ctx );
2032 Log .v (TAG , "Ready to unpack" );
2133 File app_root_file = new File (appRoot );
22- PythonUtil .unpackData (ctx , "private" , app_root_file , false );
34+ PythonUtil .unpackAsset (ctx , "private" , app_root_file , true );
35+ PythonUtil .unpackPyBundle (ctx , ctx .getApplicationInfo ().nativeLibraryDir + "/" + "libpybundle" , app_root_file , false );
2336 }
2437
2538 public static void start (Context ctx , String pythonServiceArgument ) {
39+ Intent intent = getDefaultIntent (ctx , pythonServiceArgument );
40+
41+ //foreground: {{foreground}}
42+ {% if foreground %}
43+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
44+ ctx .startForegroundService (intent );
45+ } else {
46+ ctx .startService (intent );
47+ }
48+ { % else %}
49+ ctx .startService (intent );
50+ {% endif %}
51+ }
52+
53+ static public Intent getDefaultIntent (Context ctx , String pythonServiceArgument ) {
2654 String appRoot = PythonUtil .getAppRoot (ctx );
2755 Intent intent = new Intent (ctx , Service {{ name |capitalize }}.class );
2856 intent .putExtra ("androidPrivate" , appRoot );
@@ -36,16 +64,19 @@ public static void start(Context ctx, String pythonServiceArgument) {
3664 intent .putExtra ("androidUnpack" , appRoot );
3765 intent .putExtra ("pythonPath" , appRoot + ":" + appRoot + "/lib" );
3866 intent .putExtra ("pythonServiceArgument" , pythonServiceArgument );
67+ return intent ;
68+ }
3969
40- //foreground: {{foreground}}
41- {% if foreground %}
42- if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . O ) {
43- ctx . startForegroundService ( intent );
44- } else {
45- ctx . startService ( intent );
46- }
47- { % else %}
48- ctx . startService ( intent );
49- {% endif %}
70+ @ Override
71+ protected Intent getThisDefaultIntent ( Context ctx , String pythonServiceArgument ) {
72+ return Service {{ name | capitalize }}. getDefaultIntent ( ctx , pythonServiceArgument );
73+ }
74+
75+
76+
77+ static public void stop ( Context ctx ) {
78+ Intent intent = new Intent ( ctx , Service {{ name | capitalize }}. class );
79+ ctx . stopService ( intent );
5080 }
81+
5182}
0 commit comments