Notification multiline

后端 未结 5 802
时光取名叫无心
时光取名叫无心 2020-12-28 12:53

How to make a long notification multiline. I am using the below code snippet but its not working:

NotificationCompat.Builder mBuilder = new NotificationCompa         


        
5条回答
  •  一整个雨季
    2020-12-28 13:18

    Try this code working fine with android Oreo notification channel id.

    public static int id = 0;
    private void sendNotification(String messageBody) {
    
        Log.d("FCMID","id : " + id);
        Intent intent = new Intent(this, Main2Activity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,PendingIntent.FLAG_ONE_SHOT);
    
        String channelId = "1";
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                .setSmallIcon(R.drawable.ic_notification)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
                .setContentTitle("Piml Sid")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
    
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    
        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId,
                    "Spike Bot",
                    NotificationManager.IMPORTANCE_DEFAULT);
            notificationManager.createNotificationChannel(channel);
        }
        id ++;
       notificationManager.notify(id /* ID of notification */, notificationBuilder.build());
    }
    

提交回复
热议问题