private void ShowNotificationConnected(bool show) { var nm = GetNotifyManager(); if (show) { NotificationCompat.Builder nb = new NotificationCompat.Builder(ApplicationContext); var remoteView = new RemoteViews(PackageName, Resource.Layout.layout_notify_connected); remoteView.SetTextViewText(Resource.Id.tvNotifyTitle, GetString(Resource.String.app_name)); remoteView.SetTextViewText(Resource.Id.tvNotifyCnctdWith, $"Connected with {_dsp.device.Model}"); Intent itAction = new Intent(BROAD_NOTIFY_CONNECTION); itAction.PutExtra("ACT", 0); PendingIntent piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteView.SetOnClickPendingIntent(Resource.Id.ibNotifiAction1, piAction); itAction = new Intent(BROAD_NOTIFY_CONNECTION); itAction.PutExtra("ACT", 1); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteView.SetOnClickPendingIntent(Resource.Id.ibNotifiAction2, piAction); itAction = new Intent(BROAD_NOTIFY_CONNECTION); itAction.PutExtra("ACT", 2); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteView.SetOnClickPendingIntent(Resource.Id.ibNotifiAction3, piAction); itAction = new Intent(BROAD_NOTIFY_CONNECTION); itAction.PutExtra("ACT", 3); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteView.SetOnClickPendingIntent(Resource.Id.ibNotifiAction4, piAction); Intent intent = new Intent(this, typeof(HomeActivity)); intent.PutExtra(INTENT_HOME_TAB, 0); intent.AddFlags(ActivityFlags.ClearTop); intent.AddFlags(ActivityFlags.SingleTop); PendingIntent pendingIntent = PendingIntent.GetActivity(this, IntentHelper.GetId(), intent, 0); nb.SetContentIntent(pendingIntent); nb.SetSmallIcon(Resource.Drawable.av_receiver_100_black); nb.SetOngoing(true); nb.SetCustomBigContentView(remoteView); var x = remoteView.Clone(); x.SetViewVisibility(Resource.Id.llNotifyExp, ViewStates.Gone); nb.SetCustomContentView(x); nm.Notify(notifyIdConnected, nb.Build()); } else { nm.CancelAll(); } }
private void ShowNowPlayingNotification(bool show) { if (show == isNotifyPlayerActive) { return; } Application.SynchronizationContext.Post(_ => { try { var nm = GetNotifyManager(); if (show) { var remoteViewExp = new RemoteViews(PackageName, Resource.Layout.layout_notifi_player_exp); NotificationCompat.Builder nb = new NotificationCompat.Builder(ApplicationContext); Intent intent = new Intent(this, typeof(HomeActivity)); intent.PutExtra(INTENT_HOME_TAB, 0); intent.AddFlags(ActivityFlags.ClearTop); intent.AddFlags(ActivityFlags.SingleTop); PendingIntent pendingIntent = PendingIntent.GetActivity(this, IntentHelper.GetId(), intent, 0); nb.SetContentIntent(pendingIntent); nb.SetSmallIcon(Resource.Drawable.av_receiver_100_black); nb.SetCustomBigContentView(remoteViewExp); var x = remoteViewExp.Clone(); x.SetViewVisibility(Resource.Id.llNotifyExp, ViewStates.Gone); nb.SetCustomContentView(x); nb.SetOngoing(true); var notifi = nb.Build(); nm.Notify(notifyIdPlayer, notifi); isNotifyPlayerActive = true; } else { nm.Cancel(notifyIdPlayer); isNotifyPlayerActive = false; } } catch (Exception e) { Console.WriteLine(e); } }, null); }
private void UpdateNowPlayingNotification() { Application.SynchronizationContext.Post(_ => { try { if (isNotifyPlayerActive) { var nm = GetNotifyManager(); var remoteViewExp = new RemoteViews(PackageName, Resource.Layout.layout_notifi_player_exp); remoteViewExp.SetImageViewResource(Resource.Id.ibNotifiAction3, netStatus.StatusPlay == CmdHelper.NetStatus.Status.PAUSE ? Resource.Drawable.play_100_black : Resource.Drawable.pause_100_black); Intent itAction = new Intent(BROAD_NOTIFY_PLAYER); itAction.PutExtra("ACT", 0); PendingIntent piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteViewExp.SetOnClickPendingIntent(Resource.Id.ibNotifiAction1, piAction); itAction = new Intent(BROAD_NOTIFY_PLAYER); itAction.PutExtra("ACT", 1); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteViewExp.SetOnClickPendingIntent(Resource.Id.ibNotifiAction2, piAction); itAction = new Intent(BROAD_NOTIFY_PLAYER); itAction.PutExtra("ACT", 2); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteViewExp.SetOnClickPendingIntent(Resource.Id.ibNotifiAction3, piAction); itAction = new Intent(BROAD_NOTIFY_PLAYER); itAction.PutExtra("ACT", 3); piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0); remoteViewExp.SetOnClickPendingIntent(Resource.Id.ibNotifiAction4, piAction); var titleName = netTitleName?.TitleName; var artistName = netArtistName?.ArtistName; if (cmdInputState?.Parameter == "2E") { artistName = netTitleName?.TitleName; titleName = "Bluetooth"; } if (titleName != null) { remoteViewExp.SetTextViewText(Resource.Id.tvNotifiTitle1, titleName); remoteViewExp.SetViewVisibility(Resource.Id.tvNotifiTitle1, ViewStates.Visible); } if (artistName != null) { remoteViewExp.SetTextViewText(Resource.Id.tvNotifiTitle2, artistName); remoteViewExp.SetViewVisibility(Resource.Id.tvNotifiTitle2, ViewStates.Visible); } if (netAlbumName?.AlbumName != null) { remoteViewExp.SetTextViewText(Resource.Id.tvNotifiTitle3, netAlbumName.AlbumName); remoteViewExp.SetViewVisibility(Resource.Id.tvNotifiTitle3, ViewStates.Visible); } if (netArt?.bmArt != null) { remoteViewExp.SetImageViewBitmap(Resource.Id.ivNotifiCover, netArt.bmArt); remoteViewExp.SetViewVisibility(Resource.Id.ivNotifiCover, ViewStates.Visible); } else { remoteViewExp.SetImageViewResource(Resource.Id.ivNotifiCover, Resource.Drawable.app_icon); remoteViewExp.SetViewVisibility(Resource.Id.ivNotifiCover, ViewStates.Visible); } NotificationCompat.Builder nb = new NotificationCompat.Builder(ApplicationContext); Intent intent = new Intent(this, typeof(HomeActivity)); intent.PutExtra(INTENT_HOME_TAB, 0); intent.AddFlags(ActivityFlags.ClearTop); intent.AddFlags(ActivityFlags.SingleTop); PendingIntent pendingIntent = PendingIntent.GetActivity(this, IntentHelper.GetId(), intent, 0); nb.SetContentIntent(pendingIntent); nb.SetCustomBigContentView(remoteViewExp); var x = remoteViewExp.Clone(); x.SetViewVisibility(Resource.Id.llNotifyExp, ViewStates.Gone); nb.SetCustomContentView(x); nb.SetSmallIcon(Resource.Drawable.av_receiver_100_black); nb.SetOngoing(true); nm.Notify(notifyIdPlayer, nb.Build()); } } catch (Exception e) { Console.WriteLine(e); } }, null); }