Skip to content

Commit 980dc97

Browse files
Merge pull request livecode#6558 from livecodeian/bugfix-20551
[[ Bug 20551 ]] Update Android Notification module to compile against API 23
2 parents ae085fe + 637ebd6 commit 980dc97

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

docs/notes/bugfix-20551.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Android: Update Notification module to compile against API 23

engine/src/java/com/runrev/android/NotificationModule.java

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.runrev.android;
1818

1919
import android.app.*;
20+
import android.app.Notification.Builder;
2021
import android.database.*;
2122
import android.database.sqlite.*;
2223
import android.content.*;
@@ -482,20 +483,8 @@ public static void setupStatusBarNotification(Context context)
482483
}
483484
}
484485

485-
public static void showStatusBarNotification(Context context, int p_id, String p_body, String p_title, boolean p_play_sound, int p_badge_value)
486+
private static PendingIntent createNotificationContentIntent(Context context)
486487
{
487-
// create status bar notification for activity
488-
int t_icon;
489-
t_icon = context.getResources().getIdentifier("drawable/notify_icon", null, context.getPackageName());
490-
491-
NotificationManager t_notification_manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
492-
493-
Notification t_notification = new Notification(t_icon, p_title, System.currentTimeMillis());
494-
t_notification . flags |= Notification.FLAG_AUTO_CANCEL;
495-
t_notification . number = p_badge_value;
496-
if (p_play_sound)
497-
t_notification.defaults = Notification.DEFAULT_SOUND;
498-
499488
Class t_activity_class = null;
500489

501490
String t_class_fqn = context.getPackageName() + ".mblandroid";
@@ -511,14 +500,41 @@ public static void showStatusBarNotification(Context context, int p_id, String p
511500

512501
Intent t_intent = new Intent(context, t_activity_class);
513502

514-
Intent t_cancel_intent = new Intent(context, getReceiverClass(context));
515-
t_cancel_intent.setAction(ACTION_CANCEL_NOTIFICATION);
516-
t_cancel_intent.putExtra(NOTIFY_ID, p_id);
517-
518-
t_notification.setLatestEventInfo(context.getApplicationContext(), p_title, p_body, PendingIntent.getActivity(context, 0, t_intent, 0));
519-
t_notification.deleteIntent = PendingIntent.getBroadcast(context, 0, t_cancel_intent, 0);
503+
return PendingIntent.getActivity(context, 0, t_intent, 0);
504+
}
505+
506+
private static PendingIntent createNotificationCancelIntent(Context context, int p_id)
507+
{
508+
Intent t_intent = new Intent(context, getReceiverClass(context));
509+
t_intent.setAction(ACTION_CANCEL_NOTIFICATION);
510+
t_intent.putExtra(NOTIFY_ID, p_id);
520511

521-
t_notification_manager.notify(p_id, t_notification);
512+
return PendingIntent.getBroadcast(context, 0, t_intent, 0);
513+
}
514+
515+
public static void showStatusBarNotification(Context context, int p_id, String p_body, String p_title, boolean p_play_sound, int p_badge_value)
516+
{
517+
// create status bar notification for activity
518+
int t_icon;
519+
t_icon = context.getResources().getIdentifier("drawable/notify_icon", null, context.getPackageName());
520+
521+
NotificationManager t_notification_manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
522+
523+
Notification.Builder t_builder = new Notification.Builder(context);
524+
t_builder.setSmallIcon(t_icon);
525+
t_builder.setAutoCancel(true);
526+
t_builder.setNumber(p_badge_value);
527+
528+
if (p_play_sound)
529+
t_builder.setDefaults(Notification.DEFAULT_SOUND);
530+
531+
t_builder.setContentIntent(createNotificationContentIntent(context));
532+
t_builder.setContentText(p_body);
533+
t_builder.setContentTitle(p_title);
534+
535+
t_builder.setDeleteIntent(createNotificationCancelIntent(context, p_id));
536+
537+
t_notification_manager.notify(p_id, t_builder.build());
522538
}
523539

524540
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)