expo-android-notification-listener-service
v1.1.0
Published
An Expo module for Android that allows React Native apps to monitor and interact with notifications from other apps using NotificationListenerService.
Maintainers
Readme
Expo Android NotificationListenerService
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-serviceUsage
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
- Terminal 1: Build the library
npx run build- Terminal 2: Run the example in Android Studio.
Development build app will run in emulator.
cd example
npx expo run:android- Run the example in Android Studio.
Open expo-android-notification-listener-service/example/android in Android Studio.
