wear-osandroid-wear-notification

Expanded notification


I have a notification that i want to be displayed immediately after that´s created.

my code right now:

Intent myIntent = new Intent(WearRunActivity.this, ResultsActivity.class);
    myIntent.putExtra("distance", distance);
    myIntent.putExtra("time", chronometer.getText());
    myIntent.putExtra("pace", pace);
    myIntent.putExtra("speed", speedAc);
    myIntent.putExtra("lSteps", leftSteps);
    myIntent.putExtra("rSteps", rightSteps);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    //WearRunActivity.this.startActivityIfNeeded(myIntent, 1);


    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.card_icon)
                    .setContentTitle("REPORT")
                    .setContentText(chronometer.getText())
                    .setLargeIcon(BitmapFactory.decodeResource(
                            getResources(), R.drawable.card_icon))
                    .setAutoCancel(true)
                    .setContentIntent(pendingIntent);

    notification_manager = NotificationManagerCompat.from(this);

    notification_manager.notify(1, notificationBuilder.build());

With this code, the notification is created but it is not displayed automatically on the screen. I need to swipe through all the pending notifications to search for it. What I want is that this notification is displayed on the screen automatically after it is created, any suggestions?


Solution

  • I foud a way!
    When building the notification add the line .setOngoing(True) so when the notification is sent, it will be on top of all the pending notifications and will be displayed on the screen.

    NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.card_icon)
                        .setContentTitle("Report")
                        .setContentText(chronometer.getText())
                        .setLargeIcon(BitmapFactory.decodeResource(
                                getResources(), R.drawable.card_background_blur))
                        .setAutoCancel(true)
                        .setOngoing(true)
                        .setContentIntent(pendingIntent);