Reputation: 470
I'd like to show a full screen notification when my app is receiving an incoming call. Basically the same as WhatsApp, ie. when the phone received a notification and the app is not started, I want to show a view (activity, notification, whatever you want to call it) that is taking the full size of the screen. Everything is working except one thing: the "view" is never shown in full screen, only as a classic notification.
Here's my code, pretty straightforward. Can someone pinpoint any issue in it? Am I missing some kind of permission or something? Any help would be welcomed.
Intent incomingCallDialog = new Intent(context, IncomingCallActivity.class);
incomingCallDialog.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
incomingCallDialog.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (context.getApplication() != null && ((MyApplication) context.getApplication()).getCurrentActivity() == null) {
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(context, 0,
incomingCallDialog, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentTitle(context.getString(R.string.incoming_call_from, email));
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
notificationBuilder.setContentText(caller.getName());
notificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
notificationBuilder.setCategory(NotificationCompat.CATEGORY_CALL);
notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, true);
notificationBuilder.setContentIntent(fullScreenPendingIntent);
notificationBuilder.setTimeoutAfter(30 * 1000);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setWhen(0);
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
String channelId = "my_channel";
NotificationChannel channel = new NotificationChannel(
channelId,
"channelname",
NotificationManager.IMPORTANCE_HIGH);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
manager.createNotificationChannel(channel);
notificationBuilder.setChannelId(channelId);
manager.cancel(NOTIFICATION_CALL_ID);
manager.notify(NOTIFICATION_CALL_ID, notificationBuilder.build());
} else {
context.startActivity(incomingCallDialog);
}
Upvotes: 2
Views: 747
Reputation: 46
Question:
Android - Show full-screen notification when app is in the background
Based on the documentation for setFullScreenIntent
(https://developer.android.com/reference/android/app/Notification.Builder#setFullScreenIntent(android.app.PendingIntent,%20boolean)), full-screen intents are intended for urgent, high-priority notifications such as incoming calls or alarms.
From the related article (https://source.android.com/docs/core/permissions/fsi-limits), there are guidelines on how to use this feature and limitations on its behavior, but the exact behavior can depend on the state of the device (locked /unlocked ...) and system-level restrictions.
These are untested notes based on research. While this answer is late for the original poster, I hope it is useful to anyone who encounters this issue in the future.
Upvotes: 0