react-native-callkeep-android-anhbtd
v1.0.6
Published
Android incoming call UI triggered by FCM push – foreground, background, killed
Maintainers
Readme
react-native-callkeep-android-anhbtd
Android incoming call UI triggered by FCM push. Works in foreground, background, and killed state.
Requirements
- React Native ≥ 0.73
@react-native-firebase/app+@react-native-firebase/messaginggoogle-services.jsoninandroid/app/
Installation
npm install react-native-callkeep-android-anhbtd
# or
yarn add react-native-callkeep-android-anhbtdAutolink handles the rest. No manual MainApplication edit needed.
Android setup
Add to android/build.gradle:
classpath("com.google.gms:google-services:4.4.2")Add to android/app/build.gradle:
apply plugin: "com.google.gms.google-services"Usage
index.js — register FCM handlers
import messaging from '@react-native-firebase/messaging';
import { NativeModules } from 'react-native';
messaging().setBackgroundMessageHandler(async remoteMessage => {
const data = remoteMessage.data ?? {};
if (data.type === 'incoming_call') {
const { CallKeep } = NativeModules;
await CallKeep?.showIncomingCall(
data.callId, data.callerName ?? 'Unknown',
data.callerAvatarUrl ?? null, data.callerPhone ?? null,
data.hasVideo === 'true', data.meta ?? null,
);
}
});App.tsx — initialise
import { initCallKeep, ensureNotificationPermission, CallKeep } from 'react-native-callkeep-android-anhbtd';
import messaging from '@react-native-firebase/messaging';
useEffect(() => {
ensureNotificationPermission();
// Foreground FCM
const unsub = messaging().onMessage(async ({ data = {} }) => {
if (data.type === 'incoming_call') {
await CallKeep.showIncomingCall({
callId: data.callId,
callerName: data.callerName ?? 'Unknown',
hasVideo: data.hasVideo === 'true',
});
}
});
const cleanup = initCallKeep({
navigate: (screen, params) => navigation.navigate(screen, params),
goBack: () => navigation.goBack(),
});
return () => { unsub(); cleanup(); };
}, []);FCM payload format
{
"data": {
"type": "incoming_call",
"callId": "uuid",
"callerName": "John Doe",
"callerAvatarUrl": "https://...",
"callerPhone": "+1 555 000 0000",
"hasVideo": "false",
"meta": "{\"roomId\":\"r_abc\"}"
},
"android": { "priority": "HIGH" }
}Must be
data-only (nonotificationblock) sosetBackgroundMessageHandlerfires when killed.
Events
| Event | Payload | When |
|---|---|---|
| callIncoming | IncomingCallPayload | Push received, FGS started |
| callAccepted | IncomingCallPayload | User tapped Accept |
| callDeclined | { callId } | User tapped Decline |
| callTimeout | { callId } | 45s elapsed, no action |
API
CallKeep.showIncomingCall(payload) // start ringing UI
CallKeep.getPendingCall() // read accepted call on cold start
CallKeep.endCall(callId) // end call programmatically
CallKeep.on(event, callback) // subscribe to events