From 79f2a504b57522bb3ea89511b1945c14c177a9e3 Mon Sep 17 00:00:00 2001 From: Saqib Akram Date: Fri, 7 Sep 2018 18:16:49 +0500 Subject: [PATCH 1/2] Update LocalNotifications.java Fix Android Oreo issue. --- src/android/LocalNotifications.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/android/LocalNotifications.java b/src/android/LocalNotifications.java index c00a6e5..784073d 100644 --- a/src/android/LocalNotifications.java +++ b/src/android/LocalNotifications.java @@ -69,14 +69,14 @@ public boolean execute(String action, final JSONArray args, final CallbackContex } private void showNotification(JSONArray args) throws JSONException { - // Get args + // Get args String title = args.getString(0); String dir = args.getString(1); String lang = args.getString(2); String body = args.getString(3); String tag = args.getString(4); String icon = args.getString(5); - + String NOTIFICATION_CHANNEL_ID = "my_channel_id_01"; Context context = cordova.getActivity(); Intent notificationIntent = new Intent(context, NotificationHandlerActivity.class); @@ -86,10 +86,20 @@ private void showNotification(JSONArray args) throws JSONException { int requestCode = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); + NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + NotificationCompat.Builder mBuilder = null; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + int importance = NotificationManager.IMPORTANCE_DEFAULT; + NotificationChannel notificationChannel = new NotificationChannel("ID", "Name", importance); + mNotificationManager.createNotificationChannel(notificationChannel); + mBuilder = new NotificationCompat.Builder(context, notificationChannel.getId()); + } else { + mBuilder = new NotificationCompat.Builder(context); + } // Build notifications - NotificationCompat.Builder mBuilder = - new NotificationCompat.Builder(context) + mBuilder = mBuilder .setWhen(System.currentTimeMillis()) .setContentTitle(title) .setContentText(body) @@ -103,7 +113,7 @@ private void showNotification(JSONArray args) throws JSONException { } // Show notification - NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.notify(tag, 0, mBuilder.build()); } From 7099558f58025df025482ae15c7ec6abc6907fac Mon Sep 17 00:00:00 2001 From: Saqib Akram Date: Fri, 7 Sep 2018 18:22:30 +0500 Subject: [PATCH 2/2] Update LocalNotifications.java --- src/android/LocalNotifications.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/android/LocalNotifications.java b/src/android/LocalNotifications.java index 784073d..d72cd65 100644 --- a/src/android/LocalNotifications.java +++ b/src/android/LocalNotifications.java @@ -23,6 +23,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.Random; +import android.app.NotificationChannel; /** * This class exposes methods in Cordova that can be called from JavaScript.