Skip to content

Commit 7586a80

Browse files
Merge branch 'main' into Remove-CommunityToolkit.Maui.SourceGenerators.Internals.-
2 parents bdd2007 + 987b89d commit 7586a80

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/CommunityToolkit.Maui.MediaElement/Services/MediaControlsService.android.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,12 @@ void StartForegroundServices()
157157
{
158158
NotificationManager ??= GetSystemService(NotificationService) as NotificationManager ?? throw new InvalidOperationException($"{nameof(NotificationManager)} cannot be null");
159159
notificationBuilder ??= new NotificationCompat.Builder(Platform.AppContext, "1");
160-
160+
var pendingIntent = CreateActivityPendingIntent();
161161
notificationBuilder.SetSmallIcon(Resource.Drawable.media3_notification_small_icon);
162162
notificationBuilder.SetAutoCancel(false);
163163
notificationBuilder.SetForegroundServiceBehavior(NotificationCompat.ForegroundServiceImmediate);
164164
notificationBuilder.SetVisibility(NotificationCompat.VisibilityPublic);
165+
notificationBuilder.SetContentIntent(pendingIntent);
165166

166167
CreateNotificationChannel(NotificationManager);
167168

@@ -177,4 +178,17 @@ void StartForegroundServices()
177178
StartForeground(1, notificationBuilder.Build());
178179
}
179180
}
181+
182+
static PendingIntent CreateActivityPendingIntent()
183+
{
184+
var packageName = Platform.AppContext.PackageName ?? throw new InvalidOperationException("PackageName cannot be null");
185+
var packageManager = Platform.AppContext.PackageManager ?? throw new InvalidOperationException("PackageManager cannot be null");
186+
var launchIntent = packageManager.GetLaunchIntentForPackage(packageName) ?? throw new InvalidOperationException("Launch intent cannot be null");
187+
188+
launchIntent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
189+
190+
var flags = PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable;
191+
return PendingIntent.GetActivity(Platform.AppContext, 0, launchIntent, flags)
192+
?? throw new InvalidOperationException("PendingIntent cannot be null");
193+
}
180194
}

0 commit comments

Comments
 (0)