Skip to content

Commit b9c65c1

Browse files
committed
Revert "Rework notification call as setLatestEventInfo got removed in API 23, and leads to compilation error."
This reverts commit 3534a76.
1 parent b88767d commit b9c65c1

File tree

5 files changed

+16
-120
lines changed

5 files changed

+16
-120
lines changed

pythonforandroid/bootstraps/pygame/build/src/org/renpy/android/PythonService.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.renpy.android;
22

3-
import android.os.Build;
4-
import java.lang.reflect.Method;
5-
import java.lang.reflect.InvocationTargetException;
63
import android.app.Service;
74
import android.os.IBinder;
85
import android.os.Bundle;
@@ -57,31 +54,14 @@ public int onStartCommand(Intent intent, int flags, int startId) {
5754
pythonThread = new Thread(this);
5855
pythonThread.start();
5956

60-
Notification notification;
6157
Context context = getApplicationContext();
58+
Notification notification = new Notification(context.getApplicationInfo().icon,
59+
serviceTitle,
60+
System.currentTimeMillis());
6261
Intent contextIntent = new Intent(context, PythonActivity.class);
6362
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
6463
PendingIntent.FLAG_UPDATE_CURRENT);
65-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
66-
notification = new Notification(
67-
context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis());
68-
try {
69-
// prevent using NotificationCompat, this saves 100kb on apk
70-
Method func = notification.getClass().getMethod(
71-
"setLatestEventInfo", Context.class, CharSequence.class,
72-
CharSequence.class, PendingIntent.class);
73-
func.invoke(notification, context, serviceTitle, serviceDescription, pIntent);
74-
} catch (NoSuchMethodException | IllegalAccessException |
75-
IllegalArgumentException | InvocationTargetException e) {
76-
}
77-
} else {
78-
Notification.Builder builder = new Notification.Builder(context);
79-
builder.setContentTitle(serviceTitle);
80-
builder.setContentText(serviceDescription);
81-
builder.setContentIntent(pIntent);
82-
builder.setSmallIcon(context.getApplicationInfo().icon);
83-
notification = builder.build();
84-
}
64+
notification.setLatestEventInfo(context, serviceTitle, serviceDescription, pIntent);
8565
startForeground(1, notification);
8666

8767
return START_NOT_STICKY;

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.kivy.android;
22

3-
import android.os.Build;
4-
import java.lang.reflect.Method;
5-
import java.lang.reflect.InvocationTargetException;
63
import android.app.Service;
74
import android.os.IBinder;
85
import android.os.Bundle;
@@ -91,31 +88,13 @@ protected void doStartForeground(Bundle extras) {
9188
String serviceTitle = extras.getString("serviceTitle");
9289
String serviceDescription = extras.getString("serviceDescription");
9390

94-
Notification notification;
9591
Context context = getApplicationContext();
92+
Notification notification = new Notification(context.getApplicationInfo().icon,
93+
serviceTitle, System.currentTimeMillis());
9694
Intent contextIntent = new Intent(context, PythonActivity.class);
9795
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
9896
PendingIntent.FLAG_UPDATE_CURRENT);
99-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
100-
notification = new Notification(
101-
context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis());
102-
try {
103-
// prevent using NotificationCompat, this saves 100kb on apk
104-
Method func = notification.getClass().getMethod(
105-
"setLatestEventInfo", Context.class, CharSequence.class,
106-
CharSequence.class, PendingIntent.class);
107-
func.invoke(notification, context, serviceTitle, serviceDescription, pIntent);
108-
} catch (NoSuchMethodException | IllegalAccessException |
109-
IllegalArgumentException | InvocationTargetException e) {
110-
}
111-
} else {
112-
Notification.Builder builder = new Notification.Builder(context);
113-
builder.setContentTitle(serviceTitle);
114-
builder.setContentText(serviceDescription);
115-
builder.setContentIntent(pIntent);
116-
builder.setSmallIcon(context.getApplicationInfo().icon);
117-
notification = builder.build();
118-
}
97+
notification.setLatestEventInfo(context, serviceTitle, serviceDescription, pIntent);
11998
startForeground(1, notification);
12099
}
121100

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package {{ args.package }};
22

3-
import android.os.Build;
4-
import java.lang.reflect.Method;
5-
import java.lang.reflect.InvocationTargetException;
63
import android.content.Intent;
74
import android.content.Context;
85
import android.app.Notification;
@@ -29,31 +26,13 @@ public boolean canDisplayNotification() {
2926

3027
@Override
3128
protected void doStartForeground(Bundle extras) {
32-
Notification notification;
3329
Context context = getApplicationContext();
30+
Notification notification = new Notification(context.getApplicationInfo().icon,
31+
"{{ args.name }}", System.currentTimeMillis());
3432
Intent contextIntent = new Intent(context, PythonActivity.class);
3533
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
3634
PendingIntent.FLAG_UPDATE_CURRENT);
37-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
38-
notification = new Notification(
39-
context.getApplicationInfo().icon, "{{ args.name }}", System.currentTimeMillis());
40-
try {
41-
// prevent using NotificationCompat, this saves 100kb on apk
42-
Method func = notification.getClass().getMethod(
43-
"setLatestEventInfo", Context.class, CharSequence.class,
44-
CharSequence.class, PendingIntent.class);
45-
func.invoke(notification, context, "{{ args.name }}", "{{ name| capitalize }}", pIntent);
46-
} catch (NoSuchMethodException | IllegalAccessException |
47-
IllegalArgumentException | InvocationTargetException e) {
48-
}
49-
} else {
50-
Notification.Builder builder = new Notification.Builder(context);
51-
builder.setContentTitle("{{ args.name }}");
52-
builder.setContentText("{{ name| capitalize }}");
53-
builder.setContentIntent(pIntent);
54-
builder.setSmallIcon(context.getApplicationInfo().icon);
55-
notification = builder.build();
56-
}
35+
notification.setLatestEventInfo(context, "{{ args.name }}", "{{ name| capitalize }}", pIntent);
5736
startForeground({{ service_id }}, notification);
5837
}
5938

pythonforandroid/bootstraps/webview/build/src/org/kivy/android/PythonService.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.kivy.android;
22

3-
import android.os.Build;
4-
import java.lang.reflect.Method;
5-
import java.lang.reflect.InvocationTargetException;
63
import android.app.Service;
74
import android.os.IBinder;
85
import android.os.Bundle;
@@ -90,31 +87,13 @@ protected void doStartForeground(Bundle extras) {
9087
String serviceTitle = extras.getString("serviceTitle");
9188
String serviceDescription = extras.getString("serviceDescription");
9289

93-
Notification notification;
9490
Context context = getApplicationContext();
91+
Notification notification = new Notification(context.getApplicationInfo().icon,
92+
serviceTitle, System.currentTimeMillis());
9593
Intent contextIntent = new Intent(context, PythonActivity.class);
9694
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
9795
PendingIntent.FLAG_UPDATE_CURRENT);
98-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
99-
notification = new Notification(
100-
context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis());
101-
try {
102-
// prevent using NotificationCompat, this saves 100kb on apk
103-
Method func = notification.getClass().getMethod(
104-
"setLatestEventInfo", Context.class, CharSequence.class,
105-
CharSequence.class, PendingIntent.class);
106-
func.invoke(notification, context, serviceTitle, serviceDescription, pIntent);
107-
} catch (NoSuchMethodException | IllegalAccessException |
108-
IllegalArgumentException | InvocationTargetException e) {
109-
}
110-
} else {
111-
Notification.Builder builder = new Notification.Builder(context);
112-
builder.setContentTitle(serviceTitle);
113-
builder.setContentText(serviceDescription);
114-
builder.setContentIntent(pIntent);
115-
builder.setSmallIcon(context.getApplicationInfo().icon);
116-
notification = builder.build();
117-
}
96+
notification.setLatestEventInfo(context, serviceTitle, serviceDescription, pIntent);
11897
startForeground(1, notification);
11998
}
12099

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package {{ args.package }};
22

3-
import android.os.Build;
4-
import java.lang.reflect.Method;
5-
import java.lang.reflect.InvocationTargetException;
63
import android.content.Intent;
74
import android.content.Context;
85
import android.app.Notification;
@@ -29,31 +26,13 @@ public boolean canDisplayNotification() {
2926

3027
@Override
3128
protected void doStartForeground(Bundle extras) {
32-
Notification notification;
3329
Context context = getApplicationContext();
30+
Notification notification = new Notification(context.getApplicationInfo().icon,
31+
"{{ args.name }}", System.currentTimeMillis());
3432
Intent contextIntent = new Intent(context, PythonActivity.class);
3533
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
3634
PendingIntent.FLAG_UPDATE_CURRENT);
37-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
38-
notification = new Notification(
39-
context.getApplicationInfo().icon, "{{ args.name }}", System.currentTimeMillis());
40-
try {
41-
// prevent using NotificationCompat, this saves 100kb on apk
42-
Method func = notification.getClass().getMethod(
43-
"setLatestEventInfo", Context.class, CharSequence.class,
44-
CharSequence.class, PendingIntent.class);
45-
func.invoke(notification, context, "{{ args.name }}", "{{ name| capitalize }}", pIntent);
46-
} catch (NoSuchMethodException | IllegalAccessException |
47-
IllegalArgumentException | InvocationTargetException e) {
48-
}
49-
} else {
50-
Notification.Builder builder = new Notification.Builder(context);
51-
builder.setContentTitle("{{ args.name }}");
52-
builder.setContentText("{{ name| capitalize }}");
53-
builder.setContentIntent(pIntent);
54-
builder.setSmallIcon(context.getApplicationInfo().icon);
55-
notification = builder.build();
56-
}
35+
notification.setLatestEventInfo(context, "{{ args.name }}", "{{ name| capitalize }}", pIntent);
5736
startForeground({{ service_id }}, notification);
5837
}
5938

0 commit comments

Comments
 (0)