Создать постоянное уведомление и предотвратить уведомление в строке состояния

У меня есть следующий код, который я использую для приложения для Android:

package com.authorwjf.e_notifications;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Bitmap bm = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.avatar), 
                getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height), 
                true);
        Intent intent = new Intent(this, Main.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 01, intent, Intent.FLAG_ACTIVITY_CLEAR_TASK);
        Notification.Builder builder = new Notification.Builder(getApplicationContext());
        builder.setContentTitle("This is the title");
        builder.setContentText("This is the text");
        builder.setSubText("Some sub text");
        builder.setNumber(101);
        builder.setContentIntent(pendingIntent);
        builder.setTicker("Fancy Notification");
        builder.setSmallIcon(R.drawable.ic_launcher);
        builder.setLargeIcon(bm);
        builder.setAutoCancel(true);
        builder.setPriority(0);
        Notification notification = builder.build();
        NotificationManager notificationManger = 
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManger.notify(01, notification);        
    }

}

В основном приложение при запуске создает уведомление, теперь у меня есть несколько вопросов:

  • Возможно ли, когда приложение запустится, что уведомление отображается в списке выпадающего списка, но без значка в строке состояния. то есть. обратитесь к

http://imagebin.org/226494

Может ли значок, обведенный красным, не отображаться? В конечном счете, я хотел бы создать службу, которая просто сидит в уведомлении об отключении.

  • Отправляется, чтобы уведомление в раскрывающемся списке сохранялось, т.е. если значок, обведенный синим цветом (http://imagebin.org/226494), нажато, что уведомление все еще остается?

Я новичок в Android-разработчике и просто пытаюсь понять, что я могу делать с уведомлениями.

Спасибо

Ответы

Ответ 1

  • A1: Чтобы удалить значок строки состояния, используйте этот трюк:

    builder.setSmallIcon(android.R.color.transparent); //Tested and worked in API 14
    
  • A2: Чтобы сделать предварительное уведомление, добавьте эту строку:

    builder.setOngoing(true)
    

Ответ 2

Взгляните на текущий флаг события. Я считаю, что это может создавать текущие уведомления, похожие на уведомления о соединении Wi-Fi и USB.