2222import android .database .sqlite .*;
2323import android .content .*;
2424import android .util .*;
25+ import android .os .Build ;
26+ import android .graphics .Color ;
2527
2628import java .io .*;
2729import java .util .*;
2830
31+
2932public class NotificationModule
3033{
3134 public static final String TAG = "revandroid.NotificationModule" ;
@@ -82,7 +85,6 @@ protected static void resetTimer(Context context)
8285
8386 Intent t_intent = new Intent (context , t_receiver_class );
8487 t_intent .setAction (ACTION_DISPATCH_NOTIFICATIONS );
85-
8688 PendingIntent t_pending_intent = PendingIntent .getBroadcast (context , 0 , t_intent , 0 );
8789
8890 long t_next_notification = getEarliestNotificationTime (context );
@@ -531,6 +533,25 @@ public static void showStatusBarNotification(Context context, int p_id, String p
531533 t_builder .setContentIntent (createNotificationContentIntent (context ));
532534 t_builder .setContentText (p_body );
533535 t_builder .setContentTitle (p_title );
536+
537+ // If the device runs Android OREO use NotificationChannel - Added in API level 26
538+ // Note the constant value of Build.VERSION_CODES.O is 26
539+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O )
540+ {
541+ String t_channel_id = "android_channel_id" ;
542+ String t_channel_description = "Notification Channel" ;
543+ CharSequence t_channel_name = "My Notifications" ;
544+
545+ NotificationChannel t_notification_channel = new NotificationChannel (t_channel_id , t_channel_name , NotificationManager .IMPORTANCE_MAX );
546+
547+ // Configure the notification channel.
548+ t_notification_channel .setDescription (t_channel_description );
549+ t_notification_channel .enableLights (true );
550+ t_notification_channel .enableVibration (true );
551+ t_notification_manager .createNotificationChannel (t_notification_channel );
552+
553+ t_builder .setChannelId (t_channel_id );
554+ }
534555
535556 t_builder .setDeleteIntent (createNotificationCancelIntent (context , p_id ));
536557
@@ -553,6 +574,10 @@ public boolean registerForRemoteNotifications(String senderEmail)
553574 try
554575 {
555576 Intent t_registration_intent = new Intent ("com.google.android.c2dm.intent.REGISTER" );
577+
578+ // Needed for registering devices that run Android Oreo+
579+ t_registration_intent .setPackage ("com.google.android.gms" );
580+
556581 t_registration_intent .putExtra ("app" , PendingIntent .getBroadcast (m_engine .getContext (), 0 , new Intent (), 0 ));
557582 t_registration_intent .putExtra ("sender" , senderEmail );
558583 m_engine .getContext ().startService (t_registration_intent );
@@ -606,7 +631,6 @@ public static void handleRemoteMessage(Context context, String body, String titl
606631 {
607632 long t_row_id ;
608633 t_row_id = insertNotification (context , NOTIFY_TYPE_REMOTE , System .currentTimeMillis (), body , title , user_info , play_sound , badge_value );
609-
610634 resetTimer (context );
611635 }
612636
0 commit comments