Android Display notification in status bar without extensible view

I need help to do something. I am trying to display a notification in the Android status bar.

It will inform the user that synchronization with the server is in progress.

Now I use this code and it works fine:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.stat_notify_sync).setWhen(System.currentTimeMillis()) .setAutoCancel(false).setOngoing(true); NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Notification notif = builder.getNotification(); nm.notify(1, notif); 

The only problem is that the view is created when the user expands the status bar. What I want to do is display only a small icon on the top line of the status bar with no content.

Does anyone know how to do this? Thanks in advance!

+6
source share
4 answers

It's impossible.

The rationale is this: if the user looks at the status bar and sees the icon, she must somehow understand what this icon means. Therefore, the notification bar should have a line corresponding to each icon.

I suggest creating a notification explaining how you did this in your question that synchronization is in progress; this is a great opportunity to indicate which application is being synchronized (so if any problem or synchronization is performed forever, the user knows which application needs attention).

+3
source

You can use this method to display a notification icon in the status bar.

  private void showNotification() { nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // In this sample, we'll use the same text for the ticker and the // expanded notification // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.ic_launcher, "Service Started", System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this // notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, getText(R.string.service_label), "Service Started", contentIntent); // Send the notification. // We use a layout id because it is a unique number. We use it later to // cancel. nm.notify(R.string.service_started, notification); } 
+1
source

Well, this is possible for InputMethodService, just use showStatusIcon (resource_name). But I think this is not a good idea for anything other than input services.

0
source
 Context context = TutListDownloaderService.this .getApplicationContext(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(NOTIFICATION_SERVICE); 

create notification:

 Notification updateComplete = new Notification(); updateComplete.icon = android.R.drawable.stat_notify_sync; updateComplete.tickerText = context.getText(R.string.notification_title); updateComplete.when = System.currentTimeMillis(); 

Create a pending object:

 Intent notificationIntent = new Intent(context,TutListActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); String contentTitle = context.getText(R.string.notification_title).toString(); String contentText; if (!result) { Log.w(DEBUG_TAG, "XML download and parse had errors"); contentText = context.getText(R.string.notification_info_fail).toString(); } else { contentText = context.getText( R.string.notification_info_success).toString(); } updateComplete.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 

Finally, notify the user:

 notificationManager.notify(LIST_UPDATE_NOTIFICATION, updateComplete); 
0
source

All Articles