33import android .app .Notification ;
44import android .app .NotificationChannel ;
55import android .app .NotificationManager ;
6+ import android .app .PendingIntent ;
67import android .app .Service ;
78import android .content .Context ;
89import android .content .Intent ;
1314import androidx .core .app .ActivityCompat ;
1415import androidx .core .app .NotificationCompat ;
1516import androidx .core .app .NotificationManagerCompat ;
17+ import com .chdboy .MainActivity ;
1618import com .chdboy .R ;
1719
1820public class ChdmanService extends Service {
@@ -32,24 +34,28 @@ public void onCreate() {
3234
3335 private void startForegroundNotification () {
3436 try {
37+ PendingIntent pendingIntent = createPendingIntent (this );
3538 Notification notif = new NotificationCompat .Builder (this , CHANNEL_ID )
3639 .setContentTitle ("CHDBOY" )
3740 .setContentText ("Starting compression..." )
3841 .setSmallIcon (R .drawable .ic_stat_name )
3942 .setOngoing (true )
4043 .setPriority (NotificationCompat .PRIORITY_LOW )
4144 .setCategory (NotificationCompat .CATEGORY_PROGRESS )
45+ .setContentIntent (pendingIntent )
4246 .build ();
4347 startForeground (NOTIF_ID , notif );
4448 android .util .Log .d ("ChdmanService" , "Started foreground notification" );
4549 } catch (Exception e ) {
4650 android .util .Log .e ("ChdmanService" , "Failed to start foreground: " + e .getMessage ());
4751 // Try with minimal notification
4852 try {
53+ PendingIntent pendingIntent = createPendingIntent (this );
4954 Notification minimal = new NotificationCompat .Builder (this , CHANNEL_ID )
5055 .setContentTitle ("CHDBOY" )
5156 .setContentText ("Working..." )
5257 .setSmallIcon (R .drawable .ic_stat_name )
58+ .setContentIntent (pendingIntent )
5359 .build ();
5460 startForeground (NOTIF_ID , minimal );
5561 } catch (Exception e2 ) {
@@ -96,12 +102,15 @@ private void ensureChannel() {
96102 public static void updateProgress (Context ctx , String message ) {
97103 if (!hasNotificationPermission (ctx )) return ;
98104
105+ PendingIntent pendingIntent = createPendingIntent (ctx );
99106 Notification notif = new NotificationCompat .Builder (ctx , CHANNEL_ID )
100- .setContentTitle (ctx . getString ( R . string . app_name ) )
107+ .setContentTitle ("Compressing..." )
101108 .setContentText (message )
102109 .setSmallIcon (R .drawable .ic_stat_name )
110+ .setStyle (new NotificationCompat .BigTextStyle ().bigText (message ))
103111 .setOngoing (true )
104112 .setOnlyAlertOnce (true )
113+ .setContentIntent (pendingIntent )
105114 .build ();
106115 try {
107116 NotificationManagerCompat .from (ctx ).notify (NOTIF_ID , notif );
@@ -112,13 +121,15 @@ public static void notifyDone(Context ctx, String message) {
112121 if (!hasNotificationPermission (ctx )) return ;
113122
114123 // Show completion notification with static icon
124+ PendingIntent pendingIntent = createPendingIntent (ctx );
115125 Notification notif = new NotificationCompat .Builder (ctx , CHANNEL_ID )
116126 .setContentTitle (ctx .getString (R .string .app_name ))
117127 .setContentText (message )
118128 .setSmallIcon (R .drawable .ic_stat_name )
119129 .setPriority (NotificationCompat .PRIORITY_HIGH )
120130 .setCategory (NotificationCompat .CATEGORY_STATUS )
121131 .setAutoCancel (true )
132+ .setContentIntent (pendingIntent )
122133 .build ();
123134 try {
124135 NotificationManagerCompat .from (ctx ).notify (NOTIF_ID + 1 , notif );
@@ -129,12 +140,14 @@ public static void updateIdle(Context ctx, String message) {
129140 if (!hasNotificationPermission (ctx )) return ;
130141
131142 // Show idle notification with static icon
143+ PendingIntent pendingIntent = createPendingIntent (ctx );
132144 Notification notif = new NotificationCompat .Builder (ctx , CHANNEL_ID )
133145 .setContentTitle (ctx .getString (R .string .app_name ))
134146 .setContentText (message )
135147 .setSmallIcon (R .drawable .ic_stat_name )
136148 .setOngoing (true )
137149 .setOnlyAlertOnce (true )
150+ .setContentIntent (pendingIntent )
138151 .build ();
139152 try {
140153 NotificationManagerCompat .from (ctx ).notify (NOTIF_ID , notif );
@@ -152,4 +165,14 @@ private static boolean hasNotificationPermission(Context ctx) {
152165 }
153166 return true ; // Pre-Android 13 doesn't require explicit permission
154167 }
168+
169+ private static PendingIntent createPendingIntent (Context ctx ) {
170+ Intent intent = new Intent (ctx , MainActivity .class );
171+ intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK | Intent .FLAG_ACTIVITY_CLEAR_TOP | Intent .FLAG_ACTIVITY_SINGLE_TOP );
172+ int flags = PendingIntent .FLAG_UPDATE_CURRENT ;
173+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
174+ flags |= PendingIntent .FLAG_IMMUTABLE ;
175+ }
176+ return PendingIntent .getActivity (ctx , 0 , intent , flags );
177+ }
155178}
0 commit comments