https://github.com/mgks/android-webview-fcm-sync
A lightweight utility to sync FCM tokens into Android WebView cookies for targeted push notifications.
https://github.com/mgks/android-webview-fcm-sync
android-library firebase hybrid java kotlin-library library messaging webview
Last synced: about 1 month ago
JSON representation
A lightweight utility to sync FCM tokens into Android WebView cookies for targeted push notifications.
- Host: GitHub
- URL: https://github.com/mgks/android-webview-fcm-sync
- Owner: mgks
- License: mit
- Created: 2025-12-15T23:06:07.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2026-01-26T00:43:55.000Z (5 months ago)
- Last Synced: 2026-04-01T09:32:17.013Z (3 months ago)
- Topics: android-library, firebase, hybrid, java, kotlin-library, library, messaging, webview
- Language: Kotlin
- Homepage:
- Size: 686 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Android WebView FCM Sync
[](https://jitpack.io/#mgks/android-webview-fcm-sync)
[](https://opensource.org/licenses/MIT)
A lightweight utility to synchronize Firebase Cloud Messaging (FCM) tokens into Android WebView Cookies. This allows your server to identify the web session with the specific Android device for targeted push notifications.
Extracted from the core of **[Android Smart WebView](https://github.com/mgks/Android-SmartWebView)**.

When users log in via a WebView, your server creates a web session but has no idea which Android device it belongs to, so you cannot reliably send push notifications later. This library fixes that gap by fetching the native FCM token and injecting it as a secure cookie, allowing your server to read it on page load and cleanly link the web session ID to the correct FCM device token.
## Installation
**Step 1. Add JitPack**
```groovy
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
```
**Step 2. Add Dependency**
```groovy
dependencies {
implementation 'com.github.mgks:android-webview-fcm-sync:1.0.0'
implementation 'com.google.firebase:firebase-messaging:23.4.0' // Required
}
```
## Setup Requirements
Because this library relies on Firebase, your App must be configured for Firebase:
1. Add `google-services.json` to your `app/` folder.
2. Apply the Google Services plugin in your `app/build.gradle`:
```groovy
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
```
## Usage
```kotlin
val fcmSync = SwvFcmSync()
val myUrl = "https://my-website.com"
// Call this BEFORE loading the URL (e.g. in onCreate)
fcmSync.sync(myUrl) { token ->
if (token != null) {
// Token is now in the CookieManager
// Safe to load the page now
webView.loadUrl(myUrl)
}
}
```
### Configuration
```kotlin
val config = SwvFcmSync.Config(
cookieName = "PUSH_DEVICE_ID", // Default: FCM_TOKEN
syncToConsole = true // Log actions to Logcat
)
fcmSync.sync(url, config)
```
## License
MIT
> **{ github.com/mgks }**
>
>  