如果应用程序关闭,android通知在后台? [英] android notification in background if app closed?

查看:278
本文介绍了如果应用程序关闭,android通知在后台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使我的应用程序已关闭,我也试图在Android通知栏中显示通知.

I am trying to display a notification in the Android notifications bar even if my application is closed.

我尝试搜索,但没有找到帮助的运气.

I've tried searching, but I have had no luck finding help.

新闻应用程序就是一个例子.即使手机屏幕关闭或新闻应用程序已关闭,它仍然可以发送有关最近新闻的通知,并将其显示在通知栏中.

An example of this is a news application. Even if the phone screen is off or the news application is closed, it can still send a notification for recent news and have it appear in the notification bar.

我应该如何在自己的应用程序中执行此操作?

How might I go about doing this in my own application?

推荐答案

您必须构建一个服务,该服务可以处理您的新闻并在知道新新闻时显示通知(启动后启动服务).

You have to build a Service that handles your news and shows notifications when it knows that are new news (Service Doc). The service will run in background even if your application is closed. You need a BroadcastReciever to run the service in background after the boot phase is completed. (Start service after boot).

该服务将构建您的通知,并通过 NotificationManager .

The service will build your notifications and send them through the NotificationManager.

本文可能适合您的需求

这篇关于如果应用程序关闭,android通知在后台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆