Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zworkb services #1725

Merged
merged 5 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

import org.renpy.android.Hardware;

//imports for channel definition
import android.app.NotificationManager;
import android.app.NotificationChannel;
import android.graphics.Color;

public class PythonService extends Service implements Runnable {

Expand Down Expand Up @@ -90,13 +94,13 @@ public int onStartCommand(Intent intent, int flags, int startId) {
protected void doStartForeground(Bundle extras) {
String serviceTitle = extras.getString("serviceTitle");
String serviceDescription = extras.getString("serviceDescription");

Notification notification;
Context context = getApplicationContext();
Intent contextIntent = new Intent(context, PythonActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
notification = new Notification(
context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis());
try {
Expand All @@ -109,7 +113,19 @@ protected void doStartForeground(Bundle extras) {
IllegalArgumentException | InvocationTargetException e) {
}
} else {
Notification.Builder builder = new Notification.Builder(context);
// for android 8+ we need to create our own channel
// https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1
String NOTIFICATION_CHANNEL_ID = "org.kivy.p4a"; //TODO: make this configurable
String channelName = "PythonSerice"; //TODO: make this configurable
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName,
NotificationManager.IMPORTANCE_NONE);

chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(chan);

Notification.Builder builder = new Notification.Builder(context, NOTIFICATION_CHANNEL_ID);
builder.setContentTitle(serviceTitle);
builder.setContentText(serviceDescription);
builder.setContentIntent(pIntent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@

{% if service %}
<service android:name="org.kivy.android.PythonService"
android:process=":pythonservice" />
android:process=":pythonservice"
android:exported="true"/>
{% endif %}
{% for name in service_names %}
<service android:name="{{ args.package }}.Service{{ name|capitalize }}"
android:process=":service_{{ name }}" />
android:process=":service_{{ name }}"
android:exported="true" />
{% endfor %}

{% if args.billing_pubkey %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Service{{ name|capitalize }} extends PythonService {
* {@inheritDoc}
*/
@Override
public int getStartType() {
public int startType() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've seen this change breaking things in the past. I haven't tried on device (Android 7) yet, but are we sure-ish about it?

return START_STICKY;
}
{% endif %}
Expand Down
5 changes: 3 additions & 2 deletions pythonforandroid/recipes/android/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def prebuild_arch(self, arch):
bootstrap = bootstrap_name = ctx_bootstrap

is_sdl2 = bootstrap_name in ('sdl2', 'sdl2python3', 'sdl2_gradle')
is_webview = bootstrap_name in ('webview',)
is_webview = bootstrap_name == 'webview'
is_service_only = bootstrap_name == 'service_only'

if is_sdl2 or is_webview:
if is_sdl2 or is_webview or is_service_only:
if is_sdl2:
bootstrap = 'sdl2'
java_ns = u'org.kivy.android'
Expand Down
3 changes: 2 additions & 1 deletion testapps/setup_testapp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
'blacklist-requirements': 'openssl,sqlite3',
'android-api': 27,
'ndk-api': 21,
'ndk-dir': '/home/asandy/android/crystax-ndk-10.3.2',
'sdk-dir':'/opt/android/android-sdk/',
'ndk-dir':'/opt/android/android-ndk-r17c/',
'dist-name': 'testapp_service',
'ndk-version': '10.3.2',
'bootstrap': 'service_only',
Expand Down