Android:将通知显示为活动,而不是将其添加到状态栏

发布于 2024-10-01 11:18:48 字数 92 浏览 0 评论 0原文

我是 Android 开发的新手,我想知道一种正确的方法来获取通知作为活动而不是状态栏通知。

需要明确的是,我想在屏幕上显示通知,而不是将其添加到状态栏。

I m a newbie to android development and i wanna know a right way to get notification as an activity instead of statusbar notification.

To be clear, i wanna display an notification on screen instead of adding it to status bar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

他不在意 2024-10-08 11:18:48

在这种情况下,您不应该将其称为通知。在 Android 中,通知最终出现在状态栏中,用户可以随意处理。

活动将占据整个屏幕并迫使用户立即处理它。这非常具有侵入性,用户可能会感到恼火,除非您显示的信息确实至关重要。

正确的行为是发布通知并在用户单击通知时显示您的活动,这与您的消息传递客户端或电子邮件客户端非常相似。

其他选项包括弹出对话或烤面包机消息。对话是用户必须与之交互才能消失的消息,而烤面包机消息将在短时间内可见,然后自动消失。

也许您可以更具体地说明您想向用户提供什么类型的信息?

In that case you shouldn't call it notification. In Android, a notification is something that ends up in the status bar and that the user can deal with at her own leisure.

An activity will take over the complete screen and force the user to deal with it immediately. That is very intrusive and users will likely get annoyed, unless the information you show is really crucial.

The correct behaviour is to post a notification and bring up your activity when the user clicks on the notification, very much like your messaging client or email client.

Other options are bringing up a dialogue or a toaster message. A dialogue is a message the user will have to interact with to go away, whereas a toaster message will be visible for a short time and then automatically disappear.

Maybe you could be a bit more specific about what sort of information you want to provide to the user?

Oo萌小芽oO 2024-10-08 11:18:48

当然你可以得到帮助。
我觉得您正在从网络服务收到通知作为对某些请求的响应,对吗?
如果是,那么您可以将它们显示在自定义对话框中,或者在主题已设置为 DIALOG 的活动内。

也许我问错了你的问题,也许你谈论的是有关网络、电话和事物的通知。
如果是这样,请纠正我。

谢谢!

Surely you can be helped out.
I feel that you are getting notifications from a web service as a response to some request, right?
If yes, then you can display them in a custom made dialog box, or inside an activity whose theme has been set as DIALOG.

maybe I got your question wrong, maybe your talking about the notifications about networks, calls and things.
If its so, correct me.

Thanks!

初熏 2024-10-08 11:18:48

Android 2.3 在通知上引入了一个新字段, fullScreenIntent,正是为了这个目的。在此放置一个 PendingIntent ,它将触发您想要显示的任何活动,用户除了接收常用的通知图标外,还将被发送到该活动(无论是全屏还是对话框主题)在状态栏中。从 Gingerbread 开始,这就是电话应用程序实现来电屏幕的方式。

Android 2.3 introduced a new field on Notification, fullScreenIntent, for exactly this purpose. Place a PendingIntent here that will trigger whatever activity you'd like to display, and the user will be sent to that activity (whether full-screen or dialog-themed) in addition to receiving the usual notification icon in the status bar. As of Gingerbread, this is how the Phone app implements the incoming call screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文