创建状态栏通知时,Android应用程序会显示在前面

时间:2012-02-13 13:50:27

标签: android notifications statusbar

基本上我按照以下教程介绍了如何创建状态栏通知: http://mobiforge.com/developing/story/displaying-status-bar-notifications-android

(在页面的一半使用类MainActivity.java alarmDetail.java DisplayNotification.java)

我遇到的问题是,在创建通知时,应用程序也会被带到前面;为了防止这种情况发生,我需要做出哪些改变?

提前致谢。

2 个答案:

答案 0 :(得分:0)

试试这个:调用此方法,如showNotification(“statusbar title”,ID)

NotificationManager mNM;
void showNoitification(String text, int id) {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // CharSequence text = "Batch action in progress";
    Notification notification = new Notification(
            android.R.drawable.arrow_up_float, text,
            System.currentTimeMillis());
    notification.defaults = Notification.FLAG_ONLY_ALERT_ONCE
            + Notification.FLAG_AUTO_CANCEL;
    // Intent pendingintent = new Intent(this, BlankActivity.class);
    Intent pendingintent = new Intent();
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            pendingintent, 0);
    notification.setLatestEventInfo(this, "your application", text, contentIntent);
    // notification.deleteIntent;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    mNM.notify(id, notification);

}

答案 1 :(得分:0)

在新线程中创建运行通知的服务。