作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在开发一个在后台接收短信 (sms) 的应用程序(即当应用程序关闭时)。我不知道如何从我已注册以在后台接收短信的服务通知状态栏上的用户。 NotificationCompat.Builder
类需要上下文作为其参数,我们不能将其传递到服务类中。
Whatsapp messenger 如何在收到新消息时在状态栏上通知?
我在 stackoverflow 上遇到过许多类似的问题,但没有一个能解决我的问题。请帮我解决这个问题。任何引用或小代码都会有所帮助。
最佳答案
您可以使用粘性服务,如果您的应用被终止,这样做将使您的服务重新启动:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("LocalService", "Received start id " + startId + ": " + intent);
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
return START_STICKY;
}
您可以在这里查看所有信息:
http://developer.android.com/reference/android/app/Service.html#START_STICKY
编辑:
这是一个如何使用它的例子:
http://developer.android.com/reference/android/app/Service.html#LocalServiceSample
关于android - 即使应用程序关闭,whatsapp 如何设法接收推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26758596/
我是一名优秀的程序员,十分优秀!