react-native-pjsip
react-native-pjsip copied to clipboard
Show incoming call screen when app not active on Android
Hi @datso
I have successfully developed iOS voip app using your library and I used Voip Push Notifications and Call Kit, everything works really good and thank you very much for great library.
Now I have problem with Android, first is how to show incoming call screen while phone is locked and app is not active, second problem is push notification, apple provides Voip push notifications but android does not, so I would like to hear your opinion which library to use for Android push notifications.
Once again thank you very much.
Hey, use GCM to send the notifications, this will wake up your app if you are using smth like react-native-push-notification. Once you receive the notification you should run to the similar code:
// Automatically start application when incoming call received.
if (mAppHidden) {
try {
String ns = getApplicationContext().getPackageName();
String cls = ns + ".MainActivity";
Intent intent = new Intent(getApplicationContext(), Class.forName(cls));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.EXTRA_DOCK_STATE_CAR);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.putExtra("foreground", true);
startActivity(intent);
} catch (Exception e) {
Log.w(TAG, "Failed to open application on received call", e);
}
}
job(new Runnable() {
@Override
public void run() {
// Brighten screen at least 10 seconds
PowerManager.WakeLock wl = mPowerManager.newWakeLock(
PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE | PowerManager.FULL_WAKE_LOCK,
"incoming_call"
);
wl.acquire(10000);
}
});
I'm going to write a PR or small package that could do this, but I don't have much time in this days :)
Any chance of getting a PR or package for this @datso? Appreciate everything you've done in maintaining this!
@joshelson Hey, this functionality is out of scope of the library, you can use react-native-callkit and related libs to archive the goal.
Hey @joshelson @enisit were either of you able to get this working? If so, do you have some code you could share detailing how you did so?
I've written a package (building off the code snippet above) to handle this. As of now, it is very basic and simply opens the app and triggers a js callback: https://github.com/reachifyio/react-native-voip-push-receiver