在android中创建自定义通知
在我的 android 项目中,我需要在发生特定事件时显示通知。 在我的应用程序中,我有一项在启动完成时启动的服务。该服务启动后台线程。这些线程引发事件。 现在的需求是,当事件发生时,我想在屏幕中间显示通知。这个通知类似于带有单个按钮的对话框。通知屏幕一直存在,直到用户单击按钮,这意味着当用户单击按钮时,屏幕将消失。我不知道如何在屏幕中间创建通知。
任何帮助将不胜感激..
In my android project I need to show the notification when the certain event has occurred.
In my application, I have a service which starts at boot completion. And this Service starts the background threads. These threads raises the event.
Now the requirement is, when the event occurred , i want to show the notification in the middle of the screen.this notification is similar to the dialog box with single button. The notification screen exist until the user clicked on the button,means when the user clicked on the button,the screen will disappear.I don't know how the create the notification in the middle of the screen.
Any help will be appreciated..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在方法中设置此代码并通过传递要显示的数据来调用此方法。
这是 Android 弹出窗口。它将显示在屏幕中间。
有关更多信息,请参阅:http://developer.android.com/reference/ android/app/Dialog.html ,
set this code in a method and call this method with passing data which you want to display.
this is android popup. it will display middle of the screen.
For more info, refer this: http://developer.android.com/reference/android/app/Dialog.html ,
Service 无法创建 UI,因此您需要创建一个包含所需 UI 的 Activity,并将 Intent 从 Service 发送到 Activity。
更新:
我强烈建议您从基础知识 要了解这里发生的一切,但基本上您需要:
对于#1,您有两个我能想到的明显选项,其中任何一个都应该有效:
对于#2,这是基本的 Android:
A Service can't create UI, so you'll need to create an Activity that contains the UI you want, and send an Intent from the Service to the Activity.
Update:
I really recommend that you start from the fundamentals to understand everything that's going on here, but basically you need to:
For #1, you have two obvious options that I can think of, either of which should work:
For #2, this is basic Android: