I want to show constantly small icon in the status bar
, without show the notification itself on the notification
tray of the system.
I tried using custom layout
and set the visibility of the root element to View.GONE
, or View.INVISIBLE
, but for both, the system ignores it.
I also tried to set the height of the root element but the system ignores this too.
Here is my code:
R.layout.custom_notification
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_notification"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/notif_background"
android:orientation="horizontal"
android:baselineAligned="false"/>
And the code for display the Notification
:
NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx);
mBuilder
.setSmallIcon(drawableId)
.setAutoCancel(false)
.setOngoing(true)
.setPriority(Notification.PRIORITY_MAX);
Intent resultIntent = new Intent(ctx, SettingsActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(ctx, 0, resultIntent, 0);
mBuilder.setContentIntent(resultPendingIntent);
int layout = R.layout.custom_notification ;
RemoteViews contentView = new RemoteViews(ctx.getPackageName(), layout);
contentView.setViewVisibility(R.id.custom_notification, View.INVISIBLE);
mBuilder.setContent(contentView);
nm.notify(NOTIFICATION_ID, mBuilder.build());
I'm well aware that for achieving my goal I will need not documented solution. And I am also aware that UX guidelines strongly recommending to not do such a thing. So there is no point in writing me this as an answer.