Skip to content
Back to journal
AndroidPush NotificationsFirebase

How to Add Push Notifications to a WebView Android App (Complete Guide)

CCode2Native EngineeringEngineering team
2026-02-18
Smartphone with push notification cards and Firebase logo floating above a WebView

You built a WebView app. It works great. But now you need push notifications — and you just discovered that Android WebView does not support the Web Push API. Don't panic. Here's the complete solution.

TL;DR: WebView can't receive web push notifications natively. The solution is to implement push notifications on the native Android side using Firebase Cloud Messaging (FCM), then use a JavaScript bridge to communicate between your native code and web content.

Why Web Push Doesn't Work in WebView

Before diving into the solution, let's understand the problem:

  • No Service Worker support: WebView doesn't support Service Workers the same way Chrome does. Service Workers are required for Web Push.
  • No background execution: When your app is closed, WebView can't wake up to receive notifications.
  • No push permission prompt: WebView doesn't show the browser's native push permission dialog.

This isn't a bug — it's by design. WebView is a rendering component, not a full browser. It doesn't have the infrastructure to manage push subscriptions independently.

The Architecture: Native FCM + JavaScript Bridge

Here's how push notifications work in a properly built WebView app:

  1. Firebase Cloud Messaging (FCM) handles notification delivery at the OS level
  2. Your Android app receives the notification even when the app is closed
  3. A JavaScript bridge passes the notification data to your web content when the app is open
  4. Tapping a notification opens the app and navigates to the relevant page

Step 1: Set Up Firebase

  1. Go to the Firebase Console and create a new project
  2. Add an Android app with your package name
  3. Download the google-services.json file
  4. Place it in your app's app/ directory
  5. Add the Firebase dependencies to your build.gradle

Important: Use Firebase BoM (Bill of Materials) to manage version compatibility. As of 2026, use implementation platform('com.google.firebase:firebase-bom:33.x.x') in your build.gradle.

Step 2: Create the Messaging Service

Create a class that extends FirebaseMessagingService to handle incoming notifications:

  • Override onMessageReceived() to process notifications
  • Override onNewToken() to handle FCM token refresh
  • Create a Notification Channel (required for Android 8.0+)
  • Build notifications with proper icons, titles, and deep link intents

Step 3: Build the JavaScript Bridge

The JavaScript bridge lets your web content interact with native push features:

  • getFCMToken(): Returns the device's FCM token so your server can send targeted notifications
  • requestNotificationPermission(): Triggers the native Android permission dialog
  • onNotificationReceived(callback): Called when a notification arrives while the app is in the foreground

On the web side, your JavaScript code calls these native methods through the bridge:

// Get the FCM token from native Android
const token = window.NativeBridge.getFCMToken();

// Send the token to your backend
fetch('/api/register-device', {
  method: 'POST',
  body: JSON.stringify({ token, userId: currentUser.id })
});

Step 4: Handle Notification Taps

When a user taps a notification, you want the app to open and navigate to the right page:

  • Include a url field in your notification payload
  • In your notification tap handler, pass the URL to WebView's loadUrl()
  • If the app was killed, store the URL in the launch intent and load it when WebView initializes

Common Issues and Fixes

Notifications not showing on Android 13+

Android 13 introduced a runtime notification permission (POST_NOTIFICATIONS). You must request this permission explicitly — it's no longer granted by default. Add the permission to your manifest and request it at runtime.

Notifications work in foreground but not background

Check your notification payload type. FCM has two types: notification messages (handled by the system tray automatically) and data messages (handled by your onMessageReceived). For background delivery, use notification messages or a combination of both.

Token changes after app reinstall

FCM tokens can change when the app is reinstalled or data is cleared. Always handle onNewToken() and update your backend with the new token.

Notifications not working on Xiaomi/Huawei devices

Some Chinese manufacturers restrict background processes aggressively. Users may need to manually whitelist your app in battery settings. Consider adding an in-app guide for these devices.

The Easy Way: Use a Service

If implementing FCM from scratch sounds like a lot of work, that's because it is. Services like Code2Native, Median.co, and Natively handle all of this automatically:

  • FCM integration is built into the generated app
  • OneSignal or Firebase integration with zero native code
  • JavaScript bridge for push token management is pre-built
  • Notification channels and permissions are handled automatically

FAQ

Can I use OneSignal instead of raw FCM?

Yes. OneSignal is a wrapper around FCM (and APNs for iOS) that provides a dashboard, segmentation, and analytics. It's free for up to 10,000 subscribers and is the most popular choice for WebView apps.

Do push notifications work when the app is completely closed?

Yes, when implemented natively via FCM. The Android OS delivers the notification regardless of app state. This is the entire point of using native push instead of web push.

How many push notifications can I send for free?

Firebase Cloud Messaging is completely free with no message limits. OneSignal's free tier supports up to 10,000 subscribers. For most small to medium apps, you'll never hit any limits.

C

Code2Native Engineering

Engineering team

Written by the Code2Native engineering team — the people who build and operate the cloud build pipeline.