From 0af5b5486be495e6273915a8943787f0f467d925 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Mon, 8 Jan 2024 11:45:05 +0200 Subject: [PATCH] android notifications docs --- src/SUMMARY.md | 1 + .../android_notification_foreground_service.md | 18 ++++++++++++++++++ src/guide/payment_notification.md | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 src/guide/android_notification_foreground_service.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 99dad70..d6a9d10 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -11,6 +11,7 @@ - [Listing payments](guide/list_payments.md) - [Receiving payments via mobile notifications](guide/payment_notification.md) - [iOS](guide/ios_notification_service_extension.md) + - [Android](guide/android_notification_foreground_service.md) - [Connecting to an LSP](guide/connecting_lsp.md) - [Receiving an on-chain transaction](guide/receive_onchain.md) - [Sending an on-chain transaction](guide/send_onchain.md) diff --git a/src/guide/android_notification_foreground_service.md b/src/guide/android_notification_foreground_service.md new file mode 100644 index 0000000..d8fb143 --- /dev/null +++ b/src/guide/android_notification_foreground_service.md @@ -0,0 +1,18 @@ + +# Android: using foreground service +For Android, the app is required to use a foreground service to process reliably notifications in the background. + +## Implementation steps +#### 1. Integrate foreground service +Add FirebaseMessagingService to your Android project. This service allows your app to process the incoming push notification. Then use the foreground service to process the notification in the background. +#### 2. Wake-up the app +When a push notification is received, the FirebaseMessagingService will be triggered, running the forground service. +#### 3. Connect with Breez SDK +In the foreground service, establish a connection with the Breez SDK to process the incoming payment. +#### 4. Wait for payment completion +Once connected, the app should wait for completion status from the Breez SDK that the payment has been received. +#### 5. Display a notification +After confirming the payment, display a notification. + +## Reference implementation +For a complete reference, see how we implemented it in c-breez wallet: [BreezFcmService.kt](https://github.com/breez/c-breez/blob/main/android/app/src/main/kotlin/com/cBreez/client/BreezFcmService.kt). diff --git a/src/guide/payment_notification.md b/src/guide/payment_notification.md index 3cdcc8c..c818b4f 100644 --- a/src/guide/payment_notification.md +++ b/src/guide/payment_notification.md @@ -108,3 +108,5 @@ Register the constructed URL with the Breez SDK By calling the register-payment- ### Step 4: Handling notifications when the app isn't running To ensure that your mobile application can handle payment notifications even when it is not actively running, specific implementations are required for both iOS and Android platforms. This involves waking up the app upon receiving a push notification, connecting with the Breez SDK, and then waiting for the payment to be fully received. * For iOS, please follow the steps in [iOS NotificationServiceExtension](ios_notification_service_extension.md). + +* For Android, please follow the steps in [Android foreground service](android_notification_foreground_service.md).