【问题标题】:Possible to make an Android Notification that does not call an Intent? [closed]可以制作不调用 Intent 的 Android 通知吗? [关闭]
【发布时间】:2010-09-23 14:44:57
【问题描述】:

我需要在我的应用程序运行时在状态栏中放置一个通知,但我不希望它在选中时回调我的 Activity。它只是向用户提供应用程序正在运行的信息 - 基本上是在他们按下主页按钮并将其最小化的情况下提醒。

想法?

【问题讨论】:

标签: android android-notifications


【解决方案1】:

我有同样的期望行为。我的解决方案是:

Intent intent = new Intent(this, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

另外,让通知在用户选择时自动消失

notification.flags |= Notification.FLAG_AUTO_CANCEL;

【讨论】:

    【解决方案2】:

    Intent 意图 = new Intent(this, YourActivity.class);

    或者只是

    意图意图 = new Intent();

    【讨论】:

      【解决方案3】:

      我最终想出了一个解决这个问题的方法,尽管它基本上是一个 hack。而不是将意图设置为指向 Activity 类,我使用的是 Dialog 类。

      this.notificationIntent = new Intent(this, SomeDialog.class);
      

      现在,如果用户通过 logcat 选择通知,我可以看到记录了启动活动,但似乎没有任何反应。

      这允许我发布一个在我的应用运行时保留的通知,然后在用户退出时将其关闭。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      相关资源
      最近更新 更多