Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show just small icon in status bar without showing notification

Tags:

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.

like image 549
yshahak Avatar asked Sep 18 '16 03:09

yshahak


People also ask

How do I hide notification icons in status bar?

Once you're in the app settings, you'll notice the “Notifications” submenu. Open it. There you'll see a ton of notification options on a system level. You can basically choose to minimize status bar notifications for one particular type of notification.

How do I change icon size on status bar?

Select the gear icon to go to the system settings. Now go to the “Display” settings. Look for “Display Size” or “Screen Zoom.” Slide the dot on the scale at the bottom of the screen to adjust the size.

How do I show icon on status bar?

Scrolling down the Quick Menu from the top of the screen, tap the Settings icon > "Display" > "Status bar icon manager" and then you can enable or disable the icons on the status bar.

How do you customize the status bar?

The status bar at the bottom of Office programs displays status on options that are selected to appear on the status bar. Many options are selected by default. If you want to customize the status bar, right-click it, and then click the options that you want.


1 Answers

It is not good idea to show an icon without show him any related Notification, As per developer docs,

A status bar notification requires all of the following:

  • An icon for the status bar (which you are interested in)
  • A title and expanded message for the expanded view (unless you define a custom expanded view)
  • PendingIntent, to be fired when the notification is clicked to show related info.

So if you don't want to ruin the User Experience then it's highly recommendable to follow UX guidelines,

logically: There are two parts of status bar – user (notifications) and system (other). If system allows to put something to system part – there will be so much useless icons (posted by other applications), and there will be no consistency, and it might break all of the use experience.

Found an answer which provide you way to access default status bar icon of Alarm it is here. After Root your mobile you can do it.There are some tricks on youtube doing it, Some answers on same topic suggest to show icon using Notification but put Notification Text empty so that user will only see icon, but again it's not a way.

This is code for Status bar implementation in System where Left and Right Icons(i.e System Icons) are described may you can get some lead from there. Answer that describe it is here.

like image 182
TapanHP Avatar answered Oct 06 '22 00:10

TapanHP