web-dev-qa-db-fra.com

Est-il possible de définir la notification étendue par défaut dans les notifications Big Text?

J'ai suivi cela Exemple de code

Dans Big Text Notifications section, il a dit qu'il fallait développer pour voir Big text notification forme, comme image im ci-dessous:

enter image description here

Je me demande que nous ne pouvons pas set Expanded Notification as default in Big Text Notifications?

Les gens qui savent que c'est possible ou non,

Si c'est possible,

Je te prie dis-moi comment faire ceci,

Merci,

37
Huy Tower

la documentation indique :

La vue d'ensemble d'une notification n'apparaît que lorsque la notification est développée, ce qui se produit lorsque la notification est en haut du tiroir de notification, ou lorsque l'utilisateur développe la notification d'un geste.

Donc ma réponse est non, vous ne pouvez pas l'étendre par défaut.

Il existe cependant une astuce pour pousser la notification en haut de la liste où elle serait développée. Réglez simplement la priorité sur Notification.PRIORITY_MAX et il est probable que la notification de votre application atteindra le sommet.

46
Emanuel Moecklin
Notification noti = new Notification.Builder()
... // The same notification properties as the others
.setStyle(new Notification.BigPictureStyle().bigPicture(mBitmap))
.build();

Vous changez

.setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert))

avec l'annonce

notification = new NotificationCompat.Builder(context)

Voici un exemple:

enter image description here Vous pouvez définir le code

Intent intent = new Intent(context, ReserveStatusActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
intent = new Intent(String.valueOf(PushActivity.class));
intent.putExtra("message", MESSAGE);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(PushActivity.class);
stackBuilder.addNextIntent(intent);
// PendingIntent pendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

// Android.support.v4.app.NotificationCompat.BigTextStyle bigStyle = new     NotificationCompat.BigTextStyle();
// bigStyle.bigText((CharSequence) context);

notification = new NotificationCompat.Builder(context)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(th_title)
    .setContentText(th_alert)
    .setAutoCancel(true)
 // .setStyle(new Notification.BigTextStyle().bigText(th_alert)  ตัวเก่า
 // .setStyle(new NotificationCompat.BigTextStyle().bigText(th_title))
    .setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert))
    .setContentIntent(pendingIntent)
    .setNumber(++numMessages)
    .build();

notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationManager.notify(1000, notification);
12
Pong Petrung
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText("Your Long Text here"))

simplement setStyle de votre générateur de notifications.

0
Popal

De ce code de notification, vous avez des images et du texte en gros ou plus.

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            if (Android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Lollipop) {
                mBuilder.setSmallIcon(R.drawable.small_logo);
                mBuilder.setColor(Color.parseColor("#D74F4F"));
            } else {
                mBuilder.setSmallIcon(icon);
            }

            mBuilder.setTicker(title).setWhen(when);
            mBuilder.setAutoCancel(true);
            mBuilder.setContentTitle(title);
            mBuilder.setContentIntent(intent);
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), icon));
            mBuilder.setContentText(msg);
            mBuilder.setPriority(Notification.PRIORITY_MAX);
            if (Utils.validateString(banner_path)) {
                mBuilder.setStyle(notiStyle);
            } else {
                mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
            }

            Notification noti = mBuilder.build();
            notificationManager.notify(0, noti);
0
Jackey kabra

Pas besoin de faire n'importe quel type de modification dans le fichier pour afficher plusieurs lignes de notification lors de l'utilisation de la notification push V5, supprimez le champ "style" de l'objet que vous envoyez. Automatiquement, les lignes de notification multiples seront visibles. Pour plus d'informations, votez la réponse, posez votre question. Je vais t'aider.

Pour référence, visitez cette question

0
Nitin Agarwal