【问题标题】:Android application brought to front when status bar notification is created创建状态栏通知时将 Android 应用程序置于最前面
【发布时间】:2012-02-13 13:50:27
【问题描述】:

基本上,我遵循以下关于如何创建状态栏通知的教程: http://mobiforge.com/developing/story/displaying-status-bar-notifications-android

(在页面中间使用 MainActivity.java alarmDetail.java DisplayNotification.java 类)

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

提前致谢。

【问题讨论】:

  • 选择或创建通知时是否出现在最前面?
  • 它在创建时出现在前面。

标签: android notifications statusbar


【解决方案1】:

试试这个:调用这个方法,比如 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);

}

【讨论】:

  • 如果你点击通知,你的申请不会在前面。
  • 我希望应用程序在点击通知时进入。但当前的问题是,在创建通知时,设置警报的 Activity 在前面。 (通知工作正常)
  • 是的,试试这个,即使创建了应用程序也不会排在前面,我已将待处理的 Intent 设置为空。通过使意图为空来检查...!!
  • 我刚刚尝试使用您上面的代码,创建通知时,Activity 仍处于最前面。将意图设为 null 是什么意思?
  • 我想你误解了我的问题。您的解决方案将使应用程序在单击通知时不会进入。但我的问题是,当在状态栏上创建通知时,应用程序排在前面。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多