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.
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.
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.
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With