@@ -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