2019-03-30 21:58:45 +01:00
|
|
|
package {{ args.package }};
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Context;
|
2022-12-02 21:15:34 +01:00
|
|
|
import {{ args.service_class_name }};
|
2019-03-30 21:58:45 +01:00
|
|
|
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
public class Service{{ name|capitalize }} extends {{ base_service_class }} {
|
2019-03-30 21:58:45 +01:00
|
|
|
{% if sticky %}
|
|
|
|
@Override
|
|
|
|
public int startType() {
|
|
|
|
return START_STICKY;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
@Override
|
2022-12-02 21:15:34 +01:00
|
|
|
protected int getServiceId() {
|
|
|
|
return {{ service_id }};
|
2019-03-30 21:58:45 +01:00
|
|
|
}
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
static public void start(Context ctx, String pythonServiceArgument) {
|
|
|
|
Intent intent = getDefaultIntent(ctx, pythonServiceArgument);
|
|
|
|
ctx.startService(intent);
|
2019-03-30 21:58:45 +01:00
|
|
|
}
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
static public Intent getDefaultIntent(Context ctx, String pythonServiceArgument) {
|
2019-03-30 21:58:45 +01:00
|
|
|
Intent intent = new Intent(ctx, Service{{ name|capitalize }}.class);
|
|
|
|
String argument = ctx.getFilesDir().getAbsolutePath() + "/app";
|
|
|
|
intent.putExtra("androidPrivate", ctx.getFilesDir().getAbsolutePath());
|
|
|
|
intent.putExtra("androidArgument", argument);
|
2022-12-02 21:15:34 +01:00
|
|
|
intent.putExtra("serviceTitle", "{{ args.name }}");
|
|
|
|
intent.putExtra("serviceDescription", "{{ name|capitalize }}");
|
2019-03-30 21:58:45 +01:00
|
|
|
intent.putExtra("serviceEntrypoint", "{{ entrypoint }}");
|
|
|
|
intent.putExtra("pythonName", "{{ name }}");
|
2022-12-02 21:15:34 +01:00
|
|
|
intent.putExtra("serviceStartAsForeground", "{{ foreground|lower }}");
|
2019-03-30 21:58:45 +01:00
|
|
|
intent.putExtra("pythonHome", argument);
|
|
|
|
intent.putExtra("pythonPath", argument + ":" + argument + "/lib");
|
|
|
|
intent.putExtra("pythonServiceArgument", pythonServiceArgument);
|
2022-12-02 21:15:34 +01:00
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Intent getThisDefaultIntent(Context ctx, String pythonServiceArgument) {
|
|
|
|
return Service{{ name|capitalize }}.getDefaultIntent(ctx, pythonServiceArgument);
|
2019-03-30 21:58:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static public void stop(Context ctx) {
|
|
|
|
Intent intent = new Intent(ctx, Service{{ name|capitalize }}.class);
|
|
|
|
ctx.stopService(intent);
|
|
|
|
}
|
|
|
|
}
|