Skip to content

An Expo module for Android that allows React Native apps to monitor and interact with notifications from other apps using NotificationListenerService.

Notifications You must be signed in to change notification settings

SeokyoungYou/expo-android-notification-listener-service

Repository files navigation

Expo Android NotificationListenerService

Jan-21-2025 00-44-56

npm License npm Expo SDK Android

An Expo module library that allows Expo app to monitor and interact with notifications from other apps using NotificationListenerService.

  • Support only Android
  • Compatible with Expo SDK 52 and above
  • Type-safed NotificationData

Installation

npm install expo-android-notification-listener-service

Usage

import ExpoAndroidNotificationListenerService, {
  NotificationData,
} from "expo-android-notification-listener-service";

const { hasPermission } = useCheckNotificationPermission();
const [notifications, setNotifications] = useState<NotificationData[]>([]);

useEffect(() => {
  ExpoAndroidNotificationListenerService.setAllowedPackages(ALLOWED_PACKAGES);

  const subscription = ExpoAndroidNotificationListenerService.addListener(
    "onNotificationReceived",
    (event: NotificationData) => {
      setNotifications((prev) => [...prev, event]);
    }
  );

  return () => {
    subscription.remove();
  };
}, []);

Refer to the example for more details.

Start Project in local

  1. Terminal 1: Build the library
npx run build
  1. Terminal 2: Run the example in Android Studio.

Development build app will run in emulator.

cd example
npx expo run:android
  1. Run the example in Android Studio.

Open expo-android-notification-listener-service/example/android in Android Studio.

About

An Expo module for Android that allows React Native apps to monitor and interact with notifications from other apps using NotificationListenerService.

Resources

Stars

Watchers

Forks

Packages

No packages published