gpt4 book ai didi

android - 即使应用程序关闭,whatsapp 如何设法接收推送通知?

转载 作者:行者123 更新时间:2023-11-29 00:16:10 24 4
gpt4 key购买 nike

我目前正在开发一个在后台接收短信 (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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com