扩展通知

Expanded notification

我有一个通知,希望在创建后立即显示。

我现在的代码:

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());

使用此代码,可以创建通知,但不会自动显示在屏幕上。我需要浏览所有待处理的通知来搜索它。我想要的是这个通知在创建后自动显示在屏幕上,有什么建议吗?

我找到方法了!
构建通知时添加行 .setOngoing(True) 以便在发送通知时,它将位于所有待处理通知之上,并将显示在屏幕上。

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);