FullScreen Notification
Asked Answered
E

3

8

I want to create a full screen notification.I have achieved a notification by using the following code. What changes do i need to make it a full screen notification.

    private void showNotification(String data) {

    Intent i = new Intent(this, MapsActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setContentTitle("FCM Test")
            .setContentText(data)
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
            .setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    manager.notify(0,builder.build());
}
Electuary answered 7/6, 2016 at 12:21 Comment(0)
B
9

You can convert simple notification to full screen notification just added a simple line of code builder.setFullScreenIntent(pendingIntent, true); following is full example. I hope this code help you

Full Screen Notification Code:

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(android.R.drawable.btn_star);
        builder.setContentTitle("This is title of notification");
        builder.setContentText("This is a notification Text");
        builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));

        Intent intent = new Intent(Broadcastdemo.this, ThreadDemo.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 113,intent, PendingIntent.FLAG_UPDATE_CURRENT);

        builder.setContentIntent(pendingIntent);
        builder.setAutoCancel(true);

        builder.setFullScreenIntent(pendingIntent, true);


        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.notify(115, builder.build()); 
Beaverette answered 7/5, 2017 at 10:58 Comment(1)
yes, this should be the correct answer. It still works on Android 10 (beta 6)Smokestack
H
1

On your builder, just before setContentIntent(pendingIntent); Simply add the following line: .setFullScreenIntent(pendingIntent, true);

Haldeman answered 11/12, 2020 at 22:55 Comment(0)
D
0

try to add both setStyle and setPriority as the following: (it is working fine for me)

  .setStyle(new Notification.BigTextStyle().BigText(message.Long_Message))   
  .setPriority((int)NotificationPriority.Max)
Dianthus answered 7/2, 2017 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.