Skip to content

Commit 65089bf

Browse files
committed
cleanup PR
1 parent 1223337 commit 65089bf

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonService.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
import org.renpy.android.Hardware;
2020

21+
//imports for channel definition
22+
import android.app.NotificationManager;
23+
import android.app.NotificationChannel;
24+
import android.content.Context;
25+
import android.graphics.Color;
26+
import android.os.Build;
2127

2228
public class PythonService extends Service implements Runnable {
2329

@@ -90,13 +96,13 @@ public int onStartCommand(Intent intent, int flags, int startId) {
9096
protected void doStartForeground(Bundle extras) {
9197
String serviceTitle = extras.getString("serviceTitle");
9298
String serviceDescription = extras.getString("serviceDescription");
93-
9499
Notification notification;
95100
Context context = getApplicationContext();
96101
Intent contextIntent = new Intent(context, PythonActivity.class);
97102
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
98103
PendingIntent.FLAG_UPDATE_CURRENT);
99-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
104+
105+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
100106
notification = new Notification(
101107
context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis());
102108
try {
@@ -109,7 +115,20 @@ protected void doStartForeground(Bundle extras) {
109115
IllegalArgumentException | InvocationTargetException e) {
110116
}
111117
} else {
112-
Notification.Builder builder = new Notification.Builder(context);
118+
// for android 8+ we need to create our own channel
119+
// https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1
120+
String NOTIFICATION_CHANNEL_ID = "org.kivy.p4a"; //TODO: make this configurable
121+
String channelName = "PythonSerice"; //TODO: make this configurable
122+
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName,
123+
NotificationManager.IMPORTANCE_NONE);
124+
125+
chan.setLightColor(Color.BLUE);
126+
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
127+
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
128+
assert manager != null;
129+
manager.createNotificationChannel(chan);
130+
131+
Notification.Builder builder = new Notification.Builder(context, NOTIFICATION_CHANNEL_ID);
113132
builder.setContentTitle(serviceTitle);
114133
builder.setContentText(serviceDescription);
115134
builder.setContentIntent(pIntent);

pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@
7171

7272
{% if service %}
7373
<service android:name="org.kivy.android.PythonService"
74-
android:process=":pythonservice" />
74+
android:process=":pythonservice"
75+
android:exported="true"/>
7576
{% endif %}
7677
{% for name in service_names %}
7778
<service android:name="{{ args.package }}.Service{{ name|capitalize }}"
78-
android:process=":service_{{ name }}" />
79+
android:process=":service_{{ name }}"
80+
android:exported="true" />
7981
{% endfor %}
8082

8183
{% if args.billing_pubkey %}

pythonforandroid/bootstraps/service_only/build/templates/Service.tmpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Service{{ name|capitalize }} extends PythonService {
1717
* {@inheritDoc}
1818
*/
1919
@Override
20-
public int getStartType() {
20+
public int startType() {
2121
return START_STICKY;
2222
}
2323
{% endif %}

pythonforandroid/recipes/android/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ def prebuild_arch(self, arch):
3838
bootstrap = bootstrap_name = ctx_bootstrap
3939

4040
is_sdl2 = bootstrap_name in ('sdl2', 'sdl2python3', 'sdl2_gradle')
41-
is_webview = bootstrap_name in ('webview',)
41+
is_webview = bootstrap_name == 'webview'
42+
is_service_only = bootstrap_name == 'service_only'
4243

43-
if is_sdl2 or is_webview:
44+
if is_sdl2 or is_webview or is_service_only:
4445
if is_sdl2:
4546
bootstrap = 'sdl2'
4647
java_ns = u'org.kivy.android'

testapps/setup_testapp_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
'blacklist-requirements': 'openssl,sqlite3',
88
'android-api': 27,
99
'ndk-api': 21,
10-
'ndk-dir': '/home/asandy/android/crystax-ndk-10.3.2',
10+
'sdk-dir':'/opt/android/android-sdk/',
11+
'ndk-dir':'/opt/android/android-ndk-r17c/',
1112
'dist-name': 'testapp_service',
1213
'ndk-version': '10.3.2',
1314
'bootstrap': 'service_only',

0 commit comments

Comments
 (0)