2012-07-07 5 views
10

ステータスバーにアイコンが表示されない通知を作成する方法を知りたいと思います。アイコンなしでステータスバーに通知を作成する方法、または単に非表示にする方法はありますか?

これを隠す方法はありますか?

+0

あなたは通知バーに全くのみ通知テキストまたは何をしたいが、あなたはそれをプルダウンする場合にのみ使用透明なイメージそして... –

+0

セットアイコン= 'null'なので – MAC

+0

を意味していますか? – Alabhya

答えて

-1

これを行うには、完全な透明イメージを作成し、これをアイコンとして使用します。 :)

+0

ありがとうございますが、私はステータスバーにスペースを取っていません。多分方法はありません... – Meroelyth

29

Android 4.1(APIレベル16)以降、通知のpriorityを指定することができます。そのフラグをPRIORITY_MINに設定すると、通知アイコンがステータスバーに表示されません。

notification.priority = Notification.PRIORITY_MIN; 

それともNotification.Builderを使用する場合は:

builder.setPriority(Notification.PRIORITY_MIN); 

あなたは通知のNotificationChannelIMPORTANCE_MINへのimportanceを設定する必要がAndroidの8.0オレオ(APIレベル26)のとおり:

NotificationChannel channel = 
     new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN); 
notificationManager.createNotificationChannel(channel); 
... 
builder.setChannelId(channel.getId()) 
+1

それは新しい通知チャネルシステムでAndroid 8+で動作しますか? – kolombo

+0

Android 8+で動作しません –

+0

@KoenVanLooveren Android 8+に必要な設定を含めるように投稿を更新しました – Floern

-2

ther eはアイコンなしで通知を表示する方法ではありません。

You can use transparent image. But, it take space of icon. 

@CommonsWareは:通知を上げるの主なポイントは、ステータスバーにアイコンを置くことですので、それは、このような、インタラクティブでない限り、通常、ステータスバーにアイコンを入れないようにする必要はありません常に実行されるトグルまたは情報通知として、プルダウンすることができますが、アイコンは使用しません。パラメータPRIORITY_MIN

check this answer for more detail.

3

.setPriorityこれを可能にします。

NotificationCompat notification = new NotificationCompat.Builder(this) 
       .setContentTitle(getString(R.string.app_name)) 
       .setContentText(getString(R.string.notification_text)) 
       .setSmallIcon(R.mipmap.ic_launcher) 

       //Show the notification only in NotificationDrawer. 
       //Notification will not be shown on LockScreen as well as Hidden Icon on StatusBar. 
       .setPriority(Notification.PRIORITY_MIN) 

       .build(); 
+1

@Floernの答えは何ですか? –

+0

@VladMatvienko Mineは、新しい学習者が必要とする場合の完全なコードです。 – zackygaurav

+0

それはあなたがそれを27分編集するまで、昨日ではなかった。前 –