Revision: 2430
http://sourceforge.net/p/swingme/code/2430
Author: yuranet
Date: 2021-03-28 16:56:41 +0000 (Sun, 28 Mar 2021)
Log Message:
-----------
use NotificationChannel
Modified Paths:
--------------
AndroidME/src_Android/net/yura/android/AndroidMeApp.java
AndroidME/src_MIDP/javax/microedition/midlet/MIDlet.java
Modified: AndroidME/src_Android/net/yura/android/AndroidMeApp.java
===================================================================
--- AndroidME/src_Android/net/yura/android/AndroidMeApp.java 2021-03-27 14:12:05 UTC (rev 2429)
+++ AndroidME/src_Android/net/yura/android/AndroidMeApp.java 2021-03-28 16:56:41 UTC (rev 2430)
@@ -1,6 +1,8 @@
package net.yura.android;
import android.app.Application;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -98,6 +100,7 @@
try {
setSystemProperties();
+ createNotificationChannel();
loadJadFile();
Vector<String[]> jadMidlets = getJadMidlets();
@@ -110,6 +113,29 @@
}
}
+ public static final String CHANNEL_ID = "default-notification-channel";
+
+ private void createNotificationChannel() {
+ try {
+ // Create the NotificationChannel, but only on API 26+ because
+ // the NotificationChannel class is new and not in the support library
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ CharSequence name = "Notification Channel";
+ String description = "Default Notification Channel";
+ int importance = NotificationManager.IMPORTANCE_DEFAULT;
+ NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
+ channel.setDescription(description);
+ // Register the channel with the system; you can't change the importance
+ // or other notification behaviors after this
+ NotificationManager notificationManager = getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(channel);
+ }
+ }
+ catch (Throwable th) {
+ Logger.warn("failed to create NotificationChannel: " + CHANNEL_ID, th);
+ }
+ }
+
@Override
public void onTerminate() {
super.onTerminate();
Modified: AndroidME/src_MIDP/javax/microedition/midlet/MIDlet.java
===================================================================
--- AndroidME/src_MIDP/javax/microedition/midlet/MIDlet.java 2021-03-27 14:12:05 UTC (rev 2429)
+++ AndroidME/src_MIDP/javax/microedition/midlet/MIDlet.java 2021-03-28 16:56:41 UTC (rev 2430)
@@ -385,11 +385,18 @@
PendingIntent intent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- Notification notif;
+ Notification notification;
+ // Use new API
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- // Use new API
- Notification.Builder notification = new Notification.Builder(context)
- .setContentIntent(intent)
+ Notification.Builder builder;
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
+ builder = new Notification.Builder(context, AndroidMeApp.CHANNEL_ID);
+ }
+ else {
+ builder = new Notification.Builder(context);
+ }
+
+ builder.setContentIntent(intent)
.setSmallIcon(icon)
.setContentTitle(title)
.setContentText(message)
@@ -396,27 +403,27 @@
.setAutoCancel(true);
if (number > 0) {
- notification.setNumber(number);
+ builder.setNumber(number);
}
- notif = notification.build();
+ notification = builder.build();
}
else {
- notif = new Notification(icon, message, System.currentTimeMillis());
- notif.iconLevel = 3;
- //notif.vibrate = new long[] {100,100,200,300};
- notif.defaults = Notification.DEFAULT_ALL;
- notif.ledOnMS = 100;
- notif.ledOffMS = 100;
- notif.flags |= Notification.FLAG_AUTO_CANCEL;
+ notification = new Notification(icon, message, System.currentTimeMillis());
+ notification.iconLevel = 3;
+ //notification.vibrate = new long[] {100,100,200,300};
+ notification.defaults = Notification.DEFAULT_ALL;
+ notification.ledOnMS = 100;
+ notification.ledOffMS = 100;
+ notification.flags |= Notification.FLAG_AUTO_CANCEL;
if (number > 0) {
- notif.number = number;
+ notification.number = number;
}
try {
- Method deprecatedMethod = notif.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class);
- deprecatedMethod.invoke(notif, context, title, message, intent);
+ Method deprecatedMethod = notification.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class);
+ deprecatedMethod.invoke(notification, context, title, message, intent);
} catch (Exception e) {
Logger.warn("setLatestEventInfo error", e);
}
@@ -423,7 +430,7 @@
}
NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- notifManager.notify(0, notif);
+ notifManager.notify(0, notification);
}
public void showToast(final String message,final int duration) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|