Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full Screen Notification only showing as a Heads Up

I have been banging my head against the table with this problem for 3 days now, please tell me where I have strayed.

When I am getting an incoming VoIP call, I am trying to show a full screen notification, just like the PhoneApp does. I am ok with heads up, if the user is in an immersive activity. However, I am getting only a heads up notification, and never getting a full screen. I need to notification to ignore the lock screen as well.

Here is what I am doing:

String callJson = call.toJson(uber).toString();
uber.requestWakeState(UberVoice.WAKE_STATE_FULL);

final Notification.Builder builder = new Notification.Builder(uber);
builder.setSmallIcon(R.drawable.switch_notification);
if (image != null) {
    builder.setLargeIcon(image);
}
builder.setOngoing(true);

PendingIntent inCallPendingIntent =
        PendingIntent.getActivity(uber, 234,
                UberVoice.createInCallIntent(), 0);
builder.setContentIntent(inCallPendingIntent);

builder.setContentText(body);
builder.setUsesChronometer(false);

builder.setContentTitle(title);

builder.setCategory(Notification.CATEGORY_CALL);
builder.setVisibility(Notification.VISIBILITY_PUBLIC);

builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE), AudioManager.STREAM_RING);
builder.setVibrate(new long[]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500});

builder.setPriority(Notification.PRIORITY_MAX);
builder.setTicker(title);
builder.setFullScreenIntent(inCallPendingIntent, true);

builder.addAction(R.drawable.hangup_action, "Reject", CallService.getPendingIntent(uber, callJson, CallService.REJECT));
builder.addAction(R.drawable.answer_action, "Answer", CallService.getPendingIntent(uber, callJson, CallService.ANSWER));

NotificationManager notificationManager = (NotificationManager) uber.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = builder.build();
notificationManager.notify(INCOMING_CALL_NOTIFICATION_ID, notification);

Here is the createInCallIntent code:

public static Intent createInCallIntent() {
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
            | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    intent.setClassName("<package>", IncomingCallActivity.class.getName());
    return intent;
}

And here is the IncomingCallActivity.onCreate()

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;

    getWindow().addFlags(flags);

    setContentView(R.layout.activity_incoming_call);

I have tried starting this activity directly(uber is Application reference)

Intent incomingCallIntent = new Intent(uber, IncomingCallActivity.class);
String callJson = call.toJson(uber).toString();
incomingCallIntent.putExtra("call", callJson);

incomingCallIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

uber.startActivity(incomingCallIntent);

What am I doing wrong?

like image 627
Leo Avatar asked Sep 03 '15 00:09

Leo


People also ask

How do I get full screen notifications on Android?

Notify while the app on the foreground. In order to show a full-screen intent, we need to first build the notification and set the full-screen intent to the notification. To build the intent we need a pending intent, which can be achieved using PendingIntent.

How wake up device and show an activity on top of lock screen for alarm?

Update: If you want to show the Activity on the lock screen, you need to set showForAllUsers to true. Here's the description from the Android documentation: Specify that an Activity should be shown even if the current/foreground user is different from the user of the Activity. This will also force the android.


2 Answers

If I understood your question correctly, you forgot to add flag WindowManager.LayoutParams.FLAG_FULLSCREEN in IncomingCallActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_FULLSCREEN;

    getWindow().addFlags(flags);

This combination needed to show activity while screen is locked. Hope it helps.

like image 98
Yazazzello Avatar answered Oct 23 '22 01:10

Yazazzello


Figured it out! It was something stupid just as I suspected.

In my IncomingCallActivity I had the following bit of code

public void onPause() {
    super.onPause();
    finish();
}

It turns out that something having to do with how Notifications get shown actually calls onPause, therefore finishing the activity.

Thanks to @JohanShogun for attempting to help out.

like image 5
Leo Avatar answered Oct 23 '22 00:10

Leo