Hi is there anything official Documentation about ...
# compose
j
Hi is there anything official Documentation about notifications in Compose or a sample App for that?
👀 1
c
What are you looking for specifically. Notifications are handled with an api that doesn't touch View code or compose code AFAIK. I think you used to be able to use remote views or something, but I think those were removed in Android 12/13?
FWIW I just implemented push notifications like last week in my pure compose app, but you don't touch UI code at all. It's just a builder where you set text and body essentially and the OS handles the rest for you.
j
okay yes I’ve seen notifications are a new topic for me, did the codelab here the source code https://github.com/googlecodelabs/android-kotlin-notifications okay fine. But I’m asking me how to implement that in compose without fragments, so I’m having a clean project architecture and notthing messy in a pure compose app and do you really need the Intents in cmpose?
c
Notifications have nothing to do with compose. From that example above I think all you need is a compose button that triggers a notificaiton, but the compose button on click code is identical to what you'd do in the view/fragment world.
In your compose button click event, you basically just need to post the notification as the docs show here: https://developer.android.com/training/notify-user/build-notification
j
the button is not the point. but where to go with the code from fragment for the channel build in my mainactivity I just call my navHost,
c
If you show some code I could hopefully be more helpful. I'm just guessing at what you need help with based off the original question. Sorry!
j
look at the codelab code I’m now having an receiver package and utils, but look in the fragment there they are creating the channel in the Fragment for the notifications. I don’t know where to put that part without fragments
c
Do you have a link to the exact spot you're looking at in the codelab. I haven't done that codelab before.
they are creating the notification channel in the Fragment but where should I do this in a pure compose multi page with single activity should I do that then? In the ViewModel, what would there be the best Style?
c
Since you need a context, you basically only have a few choices. fragment context (which just gives you hostings activity context) activity context application context service context (idk if you use services, but its popular when receiving a push notification from something like Firebase Cloud Messaging) but yeah. just throw that method into your activity or application class. no biggie.
If I were you, I'd throw it in my activity and call it a day. 😄
j
okay
🙃
no, no services at the end the notification has to go on exact time every day for an reminder that is set through an timepicker
👍 1
c
Gotcha. I've never done that. Usually just post notifications based on when my server tells me theres something new (new tweet, etc)
j
yeah and I’m thinking now about using alarms instead
c
good luck!
j
of notifications 🤣