1.1.0 • Published 6 months ago

expo-android-notification-listener-service v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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.