Android O - Single line Notification - like the “Android System - USB charging this device”

前端 未结 4 1204
难免孤独
难免孤独 2020-12-14 15:57

I would like to have an ongoing notification for my ForegroundService that requires as small place as possible. I like the "Android System - USB charging t

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 16:11

    I made the size of foreground service notification smaller by creating an empty custom view like this:

    
    
    
    
    

    and then creating the notification like this:

    RemoteViews notifiactionCollapsed = new RemoteViews(getPackageName(),R.layout.notification_collapsed);
        Notification notification = new NotificationCompat.Builder(this,CHANNEL_ID)
                .setSmallIcon(R.drawable.eq_icon)
                .setCustomContentView(notifiactionCollapsed)
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setShowWhen(false)
                .setContentIntent(pendingIntent)
                .setPriority(NotificationCompat.PRIORITY_LOW)
                .setOngoing(true)
                .setVisibility(NotificationCompat.VISIBILITY_SECRET)
                .build();
        startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE,
                notification);
    

    This helps in reducing the height of the notification but still I am not sure about how to hide the notification icon.

提交回复
热议问题