88using Android . Graphics ;
99using Android . Graphics . Drawables ;
1010using Android . Widget ;
11+ using tubeLoadNative . Droid . BroadcastReceivers ;
1112
1213namespace tubeLoadNative . Droid . Utils
1314{
@@ -17,14 +18,15 @@ public class NotificationHandler
1718 static Notification . Builder builder ;
1819 static NotificationManager notificationManager ;
1920 const int SONG_NOTIFICATION_ID = 0 ;
21+ const string CHANNEL_ID = "tubeload_song_notification" ;
2022
2123 static NotificationHandler ( )
2224 {
2325 Intent intent = new Intent ( Application . Context , typeof ( CurrentSong ) ) ;
2426 intent . AddFlags ( ActivityFlags . SingleTop ) ;
2527 PendingIntent pendingIntent = PendingIntent . GetActivity ( Application . Context , 0 , intent , PendingIntentFlags . UpdateCurrent ) ;
2628
27- builder = new Notification . Builder ( Application . Context ) ;
29+ builder = new Notification . Builder ( Application . Context , CHANNEL_ID ) ;
2830 builder . SetContentIntent ( pendingIntent ) ;
2931
3032 builder . SetOngoing ( true ) ;
@@ -35,6 +37,15 @@ static NotificationHandler()
3537 }
3638
3739 notificationManager = Application . Context . GetSystemService ( Context . NotificationService ) as NotificationManager ;
40+
41+ if ( Android . OS . Build . VERSION . SdkInt >= Android . OS . BuildVersionCodes . O )
42+ {
43+ /* Create or update. */
44+ NotificationChannel channel = new NotificationChannel ( CHANNEL_ID ,
45+ "tubeload song notification" ,
46+ NotificationImportance . Min ) ;
47+ notificationManager . CreateNotificationChannel ( channel ) ;
48+ }
3849 }
3950
4051 public static void BuildNotification ( String songId )
@@ -70,6 +81,7 @@ public static void BuildNotification(String songId)
7081 notificationLayoutExpanded . SetImageViewBitmap ( Resource . Id . songImg , bitmap ) ;
7182 CreateNotificationMediaActions ( notificationLayoutExpanded ) ;
7283 builder . SetCustomBigContentView ( notificationLayoutExpanded ) ;
84+ builder . SetContentTitle ( title ) ;
7385 }
7486 else
7587 {
@@ -91,21 +103,25 @@ public static void DeleteNotification()
91103 private static void CreateNotificationMediaActions ( RemoteViews notificationLayoutExpanded )
92104 {
93105 Intent prevIntent = new Intent ( "ACTION_MEDIA_BUTTON" ) ;
106+ prevIntent . SetClass ( Application . Context , typeof ( BluetoothRemoteControlReciever ) ) ;
94107 prevIntent . PutExtra ( Intent . ExtraKeyEvent , new KeyEvent ( KeyEventActions . Down , Keycode . MediaPrevious ) ) ;
95108 PendingIntent prevPendingIntent = PendingIntent . GetBroadcast ( Application . Context , 0 , prevIntent , PendingIntentFlags . UpdateCurrent ) ;
96109 notificationLayoutExpanded . SetOnClickPendingIntent ( Resource . Id . prevBtn , prevPendingIntent ) ;
97110
98111 Intent playPauseIntent = new Intent ( "ACTION_MEDIA_BUTTON" ) ;
112+ playPauseIntent . SetClass ( Application . Context , typeof ( BluetoothRemoteControlReciever ) ) ;
99113 playPauseIntent . PutExtra ( Intent . ExtraKeyEvent , new KeyEvent ( KeyEventActions . Down , Keycode . MediaPlayPause ) ) ;
100114 PendingIntent playPausePendingIntent = PendingIntent . GetBroadcast ( Application . Context , 1 , playPauseIntent , PendingIntentFlags . UpdateCurrent ) ;
101115 notificationLayoutExpanded . SetOnClickPendingIntent ( Resource . Id . playBtn , playPausePendingIntent ) ;
102116
103117 Intent nextIntent = new Intent ( "ACTION_MEDIA_BUTTON" ) ;
118+ nextIntent . SetClass ( Application . Context , typeof ( BluetoothRemoteControlReciever ) ) ;
104119 nextIntent . PutExtra ( Intent . ExtraKeyEvent , new KeyEvent ( KeyEventActions . Down , Keycode . MediaNext ) ) ;
105120 PendingIntent nextPendingIntent = PendingIntent . GetBroadcast ( Application . Context , 2 , nextIntent , PendingIntentFlags . UpdateCurrent ) ;
106121 notificationLayoutExpanded . SetOnClickPendingIntent ( Resource . Id . nextBtn , nextPendingIntent ) ;
107122
108123 Intent stopIntent = new Intent ( "ACTION_MEDIA_BUTTON" ) ;
124+ stopIntent . SetClass ( Application . Context , typeof ( BluetoothRemoteControlReciever ) ) ;
109125 stopIntent . PutExtra ( Intent . ExtraKeyEvent , new KeyEvent ( KeyEventActions . Down , Keycode . MediaStop ) ) ;
110126 PendingIntent stopPendingIntent = PendingIntent . GetBroadcast ( Application . Context , 3 , stopIntent , PendingIntentFlags . UpdateCurrent ) ;
111127 notificationLayoutExpanded . SetOnClickPendingIntent ( Resource . Id . closeBtn , stopPendingIntent ) ;
@@ -114,6 +130,7 @@ private static void CreateNotificationMediaActions(RemoteViews notificationLayou
114130 private static void CreateNotificationMediaActions ( )
115131 {
116132 Intent stopIntent = new Intent ( "ACTION_MEDIA_BUTTON" ) ;
133+ stopIntent . SetClass ( Application . Context , typeof ( BluetoothRemoteControlReciever ) ) ;
117134 stopIntent . PutExtra ( Intent . ExtraKeyEvent , new KeyEvent ( KeyEventActions . Down , Keycode . MediaStop ) ) ;
118135 PendingIntent stopPendingIntent = PendingIntent . GetBroadcast ( Application . Context , 3 , stopIntent , PendingIntentFlags . UpdateCurrent ) ;
119136 Notification . Action stopAction = new Notification . Action ( Resource . Drawable . ic_cancel_blue , string . Empty , stopPendingIntent ) ;
0 commit comments