Android仅在状态栏展开时显示通知

时间:2015-12-16 09:21:50

标签: android notifications statusbar

Android中是否可以仅在状态栏展开时显示通知?我的意思是只有当我拖动状态栏时,我才会看到通知,否则它将被隐藏。如果有可能我可以实现它?我只需要在最小视图中隐藏状态栏中的应用程序图标。Check this

2 个答案:

答案 0 :(得分:3)

实际上我自己发现,从Android 4.1(API 16)可以指定通知的优先级。如果您将该标记设置为PRIORITY_MIN,通知图标将不会显示在状态栏上,但您仍然可以查看有关展开状态栏的通知。

// Use NotificationCompat.Builder to set up our notification.
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
            this).setOngoing(true);
    notificationBuilder.setContentTitle("my_title"); 
    notificationBuilder.setSmallIcon(ic_launcher);
// Do other stuffs here.

 notificationBuilder.setPriority(Notification.PRIORITY_MIN);// Set this.

答案 1 :(得分:0)

您可以将builder.setSmallIcon(...)添加到您正在使用的Notification.BuilderNotificationCompat.Builder

您需要尝试在通知中获取小图标的代码:

   // Use NotificationCompat.Builder to set up our notification.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
   /* icon appears in device notification bar and right hand corner of
     notification */
    builder.setSmallIcon(R.drawable.ic_launcher);//Set this
   .....
相关问题