There is an application made in Android Studio. Shows videos from specific Youtube playlists. Accordingly, when a new video is uploaded to Youtube, it also appears in the application. You need to add the code so that the application shows a notification in the status bar when a new video appears. Please give a link or explain how to do it.

  • "There is an application made in Android Studio" of these words, I can make the assumption that you did not write this application, so the best advice, start writing it from scratch. But in general - you need YouTube api. Some kind of retrofit is all to follow the appearance of new videos on YouTube, and notifications - read the documentation - Sviat Volkov
  • No, got it wrong. I wrote, wrote from scratch, is the source of the program. But I'm new and do not know how to make notifications. Before asking a question here, I looked through a LOT of different instructions on how to do this, but did not understand. "But in general - you need YouTube api." My Youtube API is connected - Dmitry Proydakov
  • Well, then I apologize) they wrote to you where to go, they themselves are very easy (documentation is exhaustive). much harder problem - catching updates - Sviat Volkov

2 answers 2

You need to understand one thing in principle regarding notifications.

The initiator of the notifications should be the backend, i.e. some server that will scan YouTube and in the case of new videos initiate push notification.

All solutions on the client side, polling YouTube api at intervals, services, etc., all this will devour the user's battery and Internet.

How to integrate push notifications into the application, can be found here.
https://firebase.google.com/docs/cloud-messaging/

  • Maybe I don’t understand something, but why scan the Youtube channel itself if these videos appear automatically in my application. So the initiator of the notification should be my application, not the Firebase service. Or I do not understand correctly? - Dmitry Proydakov
  • In order for a video to appear in an application, it must be launched. If a user launches it, he will see a new video anyway, why does he also need a notification? - Eugene Krivenja
  • A push notification is just to notify the app about something even when it is not running. - Eugene Krivenja
  • If you think that when you see a Facebook, Youtube or Google+ notification, then the application on your phone initiates it? I want to disappoint you, it is not. - Eugene Krivenja
Context context = getApplicationContext(); Intent notificationIntent = new Intent(context, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Resources res = context.getResources(); Notification.Builder builder = new Notification.Builder(context); builder.setContentIntent(contentIntent) .setSmallIcon(R.drawable.ic_launcher_cat) // большая ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.hungrycat)) //.setTicker(res.getString(R.string.warning)) // тСкст Π² строкС состояния .setTicker("ПослСднСС китайскоС ΠΏΡ€Π΅Π΄ΡƒΠΏΡ€Π΅ΠΆΠ΄Π΅Π½ΠΈΠ΅!") .setWhen(System.currentTimeMillis()) .setAutoCancel(true) //.setContentTitle(res.getString(R.string.notifytitle)) // Π—Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ увСдомлСния .setContentTitle("НапоминаниС") //.setContentText(res.getString(R.string.notifytext)) .setContentText("ΠŸΠΎΡ€Π° ΠΏΠΎΠΊΠΎΡ€ΠΌΠΈΡ‚ΡŒ ΠΊΠΎΡ‚Π°"); // ВСкст увСдомлСния // Notification notification = builder.getNotification(); // Π΄ΠΎ API 16 Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFY_ID, notification); 

the creation of notifications http://developer.alexanderklimov.ru/android/notification.php is described here more accurately

  • one
    ok, I'll fix it now - Andriy Martsinkevych