1010import android .os .Build ;
1111import android .os .IBinder ;
1212
13+ import androidx .core .app .NotificationCompat ;
14+
1315import org .redwid .android .youtube .dl .TaskWorkerThread .TaskWorkerThreadListener ;
1416import org .redwid .youtube .dl .android .R ;
1517
16- import androidx .core .app .NotificationCompat ;
1718import timber .log .Timber ;
1819
1920/**
@@ -30,8 +31,10 @@ public class YoutubeDlService extends Service implements TaskWorkerThreadListene
3031 public static final String VALUE_TIME_OUT = "TIME_OUT" ;
3132
3233 public static final String NOTIFICATION_CHANNEL_ID = "youtube-dl-service" ;
34+ public static final int NOTIFICATION_ID = 111 ;
3335
3436 private TaskWorkerThread taskWorkerThread ;
37+ private NotificationManager notificationManager ;
3538
3639 private final IBinder binder = new LocalBinder ();
3740
@@ -51,6 +54,7 @@ public IBinder onBind(Intent intent)
5154 public void onCreate () {
5255 super .onCreate ();
5356 Timber .i ("onCreate()" );
57+ notificationManager = ((NotificationManager ) getSystemService (Context .NOTIFICATION_SERVICE ));
5458 startForegroundIfNeeded ();
5559 taskWorkerThread = new TaskWorkerThread (this );
5660 }
@@ -67,18 +71,23 @@ public void onStart(Intent intent, int startId) {
6771 }
6872 }
6973
74+ public Notification getNotification (String title , String text ) {
75+ return new NotificationCompat .Builder (this , NOTIFICATION_CHANNEL_ID )
76+ .setContentTitle (title )
77+ .setContentText (text )
78+ .build ();
79+ }
80+
7081 private void startForegroundIfNeeded () {
7182 if (Build .VERSION .SDK_INT >= 26 ) {
7283 final NotificationChannel channel = new NotificationChannel (NOTIFICATION_CHANNEL_ID ,
7384 getString (R .string .notification_channel_name ),
7485 NotificationManager .IMPORTANCE_DEFAULT );
86+ channel .setVibrationPattern (new long []{0L });
87+ channel .enableVibration (true );
88+ notificationManager .createNotificationChannel (channel );
7589
76- ((NotificationManager ) getSystemService (Context .NOTIFICATION_SERVICE )).createNotificationChannel (channel );
77-
78- final Notification notification = new NotificationCompat .Builder (this , NOTIFICATION_CHANNEL_ID )
79- .setContentTitle ("" )
80- .setContentText ("" ).build ();
81- startForeground (1 , notification );
90+ startForeground (NOTIFICATION_ID , getNotification ("" , "" ));
8291 }
8392 }
8493
0 commit comments