对话框启动时,通知会消失

时间:2012-12-01 18:24:36

标签: android notifications

只要我的应用程序打开,我就会有一个通知应该继续运行。它运行良好,它会在触发对话框的某个时刻消失。

以下是代码段:

public class SecuriteHaute extends Service{

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    final static String ACTION = "NotifyServiceAction";
    final static String STOP_SERVICE = "";
    final static int RQS_STOP_SERVICE = 1;


    private static final int MY_NOTIFICATION_ID=1;
    private NotificationManager notificationManager;
    private Notification myNotification;

    @Override
    public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ACTION);

    // Send Notification
    notificationManager =
     (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    myNotification = new Notification(R.drawable.logo_relief_violet_icone,
      "Sécurité haute",
      System.currentTimeMillis());
    Context context = getApplicationContext();
    String notificationTitle = "Sécurité haute";
    String notificationText = "";
    Intent myIntent = new Intent(Intent.ACTION_VIEW);
    PendingIntent pendingIntent
      = PendingIntent.getActivity(getBaseContext(),
        0, myIntent,
        Intent.FLAG_ACTIVITY_NEW_TASK);
        myNotification.defaults |= Notification.DEFAULT_SOUND;
        myNotification.setLatestEventInfo(context,
                notificationTitle,
                notificationText,
                pendingIntent);
        myNotification.flags|=Notification.FLAG_NO_CLEAR;
        myNotification.flags|=Notification.FLAG_ONGOING_EVENT;
        myNotification.flags|=Notification.FLAG_FOREGROUND_SERVICE;
        notificationManager.notify(MY_NOTIFICATION_ID, myNotification);

        return super.onStartCommand(intent, flags, startId);
        }   
}

我在这里错过了什么吗?

0 个答案:

没有答案