I'm developing an voip call app. What I need to do is bring activity to the foreground when receiving incoming call. I'm using Twilio in application and I start the call when push message receive.
The problem is I'm trying to show up activity when receiving any call so the user can easily accept or decline the call.
I try to display activity while using setFullScreenIntent but its not work.
How can I bring activity to the foreground without touching notification when receiving call ?
private static final int FULL_SCREEN_ID = 999;
private static final String CHANNEL_ID = "FULL_SCREEN_INTENT";
private void showFullScreenNotification(){
NotificationManager voipNotificationManager;
// Voip Notification Channel
voipNotificationManager = (NotificationManager) this.getSystemService(
Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID, "Notification",
NotificationManager.IMPORTANCE_HIGH);
channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
channel.setImportance(NotificationManager.IMPORTANCE_HIGH);
channel.enableLights(true);
if (voipNotificationManager != null) {
voipNotificationManager.createNotificationChannel(channel);
}
}
Intent fullScreenIntent = new Intent(this, FullScreenIntent.class);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("My notification")
.setContentText("Hello guys!")
//.setOnlyAlertOnce(false)
.setCategory(NotificationCompat.CATEGORY_CALL)
//.setOngoing(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setFullScreenIntent(fullScreenPendingIntent, true);
builder.build();
voipNotificationManager.notify(FULL_SCREEN_ID,builder.build());
}
I also tried these solutions