android如何删除左上角屏幕上的通知小图标



我有这个构建通知的代码,我需要删除左上角屏幕上的小图标,我需要询问是否有任何方法可以在创建通知时阻止显示这个图标

        String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager notificationManager = 
            (NotificationManager) getSystemService(ns);
    RemoteViews notificationView = new RemoteViews(getPackageName(),
            R.layout.mynotification);
    Notification.Builder notification = new Notification.Builder(
        getApplicationContext())
.setTicker(tickerText)
    .setSmallIcon(R.drawable.ic_launcher)// here how can i make it null or transparent
.setAutoCancel(true)
    .setContentIntent(mContentIntent)
    .setVibrate(mVibratePattern)
    .setContent(notificationView);

    //the intent that is started when the notification is clicked (works)
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, 
            notificationIntent, 0);

    //this is the intent that is supposed to be called when the 
    //button is clicked
    Intent switchIntent = new Intent(this, switchButtonListener.class);
    PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, 
            switchIntent,  PendingIntent.FLAG_UPDATE_CURRENT);
    notificationView.setOnClickPendingIntent(R.id.closeOnFlash, 
            pendingSwitchIntent);
    notificationView.setOnClickPendingIntent(R.id.appName, 
            pendingSwitchIntent);
    Notification not = notification.build();
    not.flags=Notification.FLAG_ONGOING_EVENT;
    notificationManager.notify(1, not);

我需要将通知留在状态栏上,但不在左上角显示小图标

好了,现在我找到了解决方案:O只需要制作这个

.setSmallIcon(android.R.color.transparent)

最新更新