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

后端 未结 5 941
陌清茗
陌清茗 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);
    

提交回复
热议问题