How to create a Spotify-like Notification


#1

Hi!
I want to create a persistent local notification for android.

Unfortunately there are only plugins and documentation about Push-Plugins for Firebase etc.
But I want a simple notification, that pops up when a button is pressend (like the Spotify Play-Button).

So no Firebase connection or Event Listener etc. The trigger for the notification should be just the button itself. The notification should display as long as the user stops a song or closes the app.

(And btw: I’d like to put a “Pause”-Button inside the notification, just like Spotify does. But I can’t find anything about that…)

Is there any documentation available (preferably for Angular 2 + {N})?

Thanks for your help!


#2

I don’t know about the interactive notifications, don’t think that is available just yet. but here is a plugin for local notifications.

You trigger them locally within the app. You can also schedule them to run at a specific time.


#3

Thx,
but this plugin isn’t the thing I’m searching for.
You can only schedule notifications (and they’ll only pop up if the app is closed), as far as I know…

I don’t understand, why {N} doesn’t offer a direct way to push notifications while running the app… (Even if it’s without interaction…)

There must be something?


#4

I had a lot of luck with the ‘fancy alert’ plugin that I use in my Practice Buddy app. Have you checked it out?


#5

Hi @tarek,

But I want a simple notification, that pops up when a button is pressend (like the Spotify Play-Button).

Are you talking about the element circled in red in the screenshot below? If so, this isn’t a local notification. It is part of the app. You would create it like any other element - probably using a GridLayout.

This isn’t something that Nativescript would provide out of the box as it isn’t a built-in control but something you would have to create yourself.


#6

looks like a ‘toast’ style notification - there’s a plugin for that!


#7

No, I really mean notifications:


#8

ahhh finally I understand. This looks like a custom plugin to me. I’m trying to trigger one on iOS - is it Android only?


#9

In iOS, I guess that would be called a “Notification Centre widget” rather than a “notification”. Not sure what the Android equivalent is.


#10

Would it be possible to create a simple Notification without the buttons (Maybe just an event, which is triggered when clicking on the notification)?

Or do I also need a custom plugin even for a simple notification?


#11

Looks like you’re just wanting the android notifications with buttons. You don’t want the push-plugin or local notifications plugins (they don’t handle these use cases last I checked). What you want is to access the android Notifications directly to build this out. It’s possible with NativeScript but I have not seen anyone with an abstraction to simplify the process with the native code calls.

https://developer.android.com/guide/topics/ui/notifiers/notifications.html

Would love to dig into this myself :smile: and I might set aside some time later this week to take on and help out if you have trouble getting it to work.


#12

@bradwaynemartin Could you achieve something?

Because I honestly have no idea where to start… :grimacing:


#13

20 days now…
Any updates? I’d love to implement these simple notifications…


#14

@tarek

With all due respect, if they were simple, you should have implemented them already, no?

@bradwaynemartin has provided you with a good point to start with. You can start small, and build a simple notification, so you can also feel how accessing native APIs works, then write a notification service based off an Android tutorial, and then follow the steps in the Controlling Media Playback on the Lock Screen paragraph to build yourself what you need.