From b9c65c1d30d0da8aa4b830eee4fbfb0482daab68 Mon Sep 17 00:00:00 2001 From: Ian Blenke Date: Wed, 16 May 2018 13:25:00 -0400 Subject: [PATCH] Revert "Rework notification call as setLatestEventInfo got removed in API 23, and leads to compilation error." This reverts commit 3534a761b17040755accf941f898cc66b905e8db. --- .../src/org/renpy/android/PythonService.java | 28 +++---------------- .../java/org/kivy/android/PythonService.java | 27 ++---------------- .../sdl2/build/templates/Service.tmpl.java | 27 ++---------------- .../src/org/kivy/android/PythonService.java | 27 ++---------------- .../webview/build/templates/Service.tmpl.java | 27 ++---------------- 5 files changed, 16 insertions(+), 120 deletions(-) diff --git a/pythonforandroid/bootstraps/pygame/build/src/org/renpy/android/PythonService.java b/pythonforandroid/bootstraps/pygame/build/src/org/renpy/android/PythonService.java index 07f9c88653..321ee6094d 100644 --- a/pythonforandroid/bootstraps/pygame/build/src/org/renpy/android/PythonService.java +++ b/pythonforandroid/bootstraps/pygame/build/src/org/renpy/android/PythonService.java @@ -1,8 +1,5 @@ package org.renpy.android; -import android.os.Build; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; import android.app.Service; import android.os.IBinder; import android.os.Bundle; @@ -57,31 +54,14 @@ public int onStartCommand(Intent intent, int flags, int startId) { pythonThread = new Thread(this); pythonThread.start(); - Notification notification; Context context = getApplicationContext(); + Notification notification = new Notification(context.getApplicationInfo().icon, + serviceTitle, + System.currentTimeMillis()); 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) { - notification = new Notification( - context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis()); - try { - // prevent using NotificationCompat, this saves 100kb on apk - Method func = notification.getClass().getMethod( - "setLatestEventInfo", Context.class, CharSequence.class, - CharSequence.class, PendingIntent.class); - func.invoke(notification, context, serviceTitle, serviceDescription, pIntent); - } catch (NoSuchMethodException | IllegalAccessException | - IllegalArgumentException | InvocationTargetException e) { - } - } else { - Notification.Builder builder = new Notification.Builder(context); - builder.setContentTitle(serviceTitle); - builder.setContentText(serviceDescription); - builder.setContentIntent(pIntent); - builder.setSmallIcon(context.getApplicationInfo().icon); - notification = builder.build(); - } + notification.setLatestEventInfo(context, serviceTitle, serviceDescription, pIntent); startForeground(1, notification); return START_NOT_STICKY; diff --git a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonService.java b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonService.java index 046dc182f9..ea1c9855ae 100644 --- a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonService.java +++ b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonService.java @@ -1,8 +1,5 @@ package org.kivy.android; -import android.os.Build; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; import android.app.Service; import android.os.IBinder; import android.os.Bundle; @@ -91,31 +88,13 @@ protected void doStartForeground(Bundle extras) { String serviceTitle = extras.getString("serviceTitle"); String serviceDescription = extras.getString("serviceDescription"); - Notification notification; Context context = getApplicationContext(); + Notification notification = new Notification(context.getApplicationInfo().icon, + serviceTitle, System.currentTimeMillis()); 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) { - notification = new Notification( - context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis()); - try { - // prevent using NotificationCompat, this saves 100kb on apk - Method func = notification.getClass().getMethod( - "setLatestEventInfo", Context.class, CharSequence.class, - CharSequence.class, PendingIntent.class); - func.invoke(notification, context, serviceTitle, serviceDescription, pIntent); - } catch (NoSuchMethodException | IllegalAccessException | - IllegalArgumentException | InvocationTargetException e) { - } - } else { - Notification.Builder builder = new Notification.Builder(context); - builder.setContentTitle(serviceTitle); - builder.setContentText(serviceDescription); - builder.setContentIntent(pIntent); - builder.setSmallIcon(context.getApplicationInfo().icon); - notification = builder.build(); - } + notification.setLatestEventInfo(context, serviceTitle, serviceDescription, pIntent); startForeground(1, notification); } diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/Service.tmpl.java b/pythonforandroid/bootstraps/sdl2/build/templates/Service.tmpl.java index 3ed10c2690..0b94ea723f 100644 --- a/pythonforandroid/bootstraps/sdl2/build/templates/Service.tmpl.java +++ b/pythonforandroid/bootstraps/sdl2/build/templates/Service.tmpl.java @@ -1,8 +1,5 @@ package {{ args.package }}; -import android.os.Build; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; import android.content.Intent; import android.content.Context; import android.app.Notification; @@ -29,31 +26,13 @@ public boolean canDisplayNotification() { @Override protected void doStartForeground(Bundle extras) { - Notification notification; Context context = getApplicationContext(); + Notification notification = new Notification(context.getApplicationInfo().icon, + "{{ args.name }}", System.currentTimeMillis()); 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) { - notification = new Notification( - context.getApplicationInfo().icon, "{{ args.name }}", System.currentTimeMillis()); - try { - // prevent using NotificationCompat, this saves 100kb on apk - Method func = notification.getClass().getMethod( - "setLatestEventInfo", Context.class, CharSequence.class, - CharSequence.class, PendingIntent.class); - func.invoke(notification, context, "{{ args.name }}", "{{ name| capitalize }}", pIntent); - } catch (NoSuchMethodException | IllegalAccessException | - IllegalArgumentException | InvocationTargetException e) { - } - } else { - Notification.Builder builder = new Notification.Builder(context); - builder.setContentTitle("{{ args.name }}"); - builder.setContentText("{{ name| capitalize }}"); - builder.setContentIntent(pIntent); - builder.setSmallIcon(context.getApplicationInfo().icon); - notification = builder.build(); - } + notification.setLatestEventInfo(context, "{{ args.name }}", "{{ name| capitalize }}", pIntent); startForeground({{ service_id }}, notification); } diff --git a/pythonforandroid/bootstraps/webview/build/src/org/kivy/android/PythonService.java b/pythonforandroid/bootstraps/webview/build/src/org/kivy/android/PythonService.java index 9a29002197..f8dde3e0d2 100644 --- a/pythonforandroid/bootstraps/webview/build/src/org/kivy/android/PythonService.java +++ b/pythonforandroid/bootstraps/webview/build/src/org/kivy/android/PythonService.java @@ -1,8 +1,5 @@ package org.kivy.android; -import android.os.Build; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; import android.app.Service; import android.os.IBinder; import android.os.Bundle; @@ -90,31 +87,13 @@ protected void doStartForeground(Bundle extras) { String serviceTitle = extras.getString("serviceTitle"); String serviceDescription = extras.getString("serviceDescription"); - Notification notification; Context context = getApplicationContext(); + Notification notification = new Notification(context.getApplicationInfo().icon, + serviceTitle, System.currentTimeMillis()); 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) { - notification = new Notification( - context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis()); - try { - // prevent using NotificationCompat, this saves 100kb on apk - Method func = notification.getClass().getMethod( - "setLatestEventInfo", Context.class, CharSequence.class, - CharSequence.class, PendingIntent.class); - func.invoke(notification, context, serviceTitle, serviceDescription, pIntent); - } catch (NoSuchMethodException | IllegalAccessException | - IllegalArgumentException | InvocationTargetException e) { - } - } else { - Notification.Builder builder = new Notification.Builder(context); - builder.setContentTitle(serviceTitle); - builder.setContentText(serviceDescription); - builder.setContentIntent(pIntent); - builder.setSmallIcon(context.getApplicationInfo().icon); - notification = builder.build(); - } + notification.setLatestEventInfo(context, serviceTitle, serviceDescription, pIntent); startForeground(1, notification); } diff --git a/pythonforandroid/bootstraps/webview/build/templates/Service.tmpl.java b/pythonforandroid/bootstraps/webview/build/templates/Service.tmpl.java index e835388ede..bf87996212 100644 --- a/pythonforandroid/bootstraps/webview/build/templates/Service.tmpl.java +++ b/pythonforandroid/bootstraps/webview/build/templates/Service.tmpl.java @@ -1,8 +1,5 @@ package {{ args.package }}; -import android.os.Build; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; import android.content.Intent; import android.content.Context; import android.app.Notification; @@ -29,31 +26,13 @@ public boolean canDisplayNotification() { @Override protected void doStartForeground(Bundle extras) { - Notification notification; Context context = getApplicationContext(); + Notification notification = new Notification(context.getApplicationInfo().icon, + "{{ args.name }}", System.currentTimeMillis()); 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) { - notification = new Notification( - context.getApplicationInfo().icon, "{{ args.name }}", System.currentTimeMillis()); - try { - // prevent using NotificationCompat, this saves 100kb on apk - Method func = notification.getClass().getMethod( - "setLatestEventInfo", Context.class, CharSequence.class, - CharSequence.class, PendingIntent.class); - func.invoke(notification, context, "{{ args.name }}", "{{ name| capitalize }}", pIntent); - } catch (NoSuchMethodException | IllegalAccessException | - IllegalArgumentException | InvocationTargetException e) { - } - } else { - Notification.Builder builder = new Notification.Builder(context); - builder.setContentTitle("{{ args.name }}"); - builder.setContentText("{{ name| capitalize }}"); - builder.setContentIntent(pIntent); - builder.setSmallIcon(context.getApplicationInfo().icon); - notification = builder.build(); - } + notification.setLatestEventInfo(context, "{{ args.name }}", "{{ name| capitalize }}", pIntent); startForeground({{ service_id }}, notification); }