Is possible set Expanded Notification as default in Big Text Notifications?

后端 未结 5 942
陌清茗
陌清茗 2020-12-05 06:27

I followed this Sample Code

In Big Text Notifications section, he said that need expand to see Big text notification form, as image im belo

相关标签:
5条回答
  • 2020-12-05 06:52
    Notification noti = new Notification.Builder()
    ... // The same notification properties as the others
    .setStyle(new Notification.BigPictureStyle().bigPicture(mBitmap))
    .build();
    

    You change

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

    along with the announcement

    notification = new NotificationCompat.Builder(context)
    

    Here is an example:

    You can set 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);
    
    0 讨论(0)
  • 2020-12-05 06:52
    notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText("Your Long Text here"))
    

    simply setStyle of your notification builder.

    0 讨论(0)
  • 2020-12-05 07:02

    No need of doing any kind of modification in the any file for showing of multiple lines of Notification while using Push Notification V5, remove the field "style", from the object you are sending. Automatically the Multiple lines of notification will be seen. For more information, upvote the answer, ask your query. I will help you out.

    For reference, visit this question

    0 讨论(0)
  • 2020-12-05 07:03

    From this notification code you have got images, and big text or more.

    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 讨论(0)
  • 2020-12-05 07:13

    The documentation states:

    A notification's big view appears only when the notification is expanded, which happens when the notification is at the top of the notification drawer, or when the user expands the notification with a gesture.

    So my answer is no, you can't expand it by default.

    There is however a trick to push the notification to the top of the list where it would be expanded. Simply set the Priority to Notification.PRIORITY_MAX and chances are that your app's notification will make it to the top.

    0 讨论(0)
提交回复
热议问题