如何在Flutter中通过HTTP api从后台发送通知(无推送通知)? [英] How to send notification from the background via an HTTP api (without push notifications) in Flutter?

查看:286
本文介绍了如何在Flutter中通过HTTP api从后台发送通知(无推送通知)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用Java开发一个Android应用程序,该应用程序使用GcmTaskService安排服务并使用HttpsURLConnection在后台发出HTTP请求(大约每10分钟),如果内容更改,它将向用户发送通知. .这可能不是执行此操作的最佳方法,但是它起作用了,对我来说就足够了.

So, I was working on a Android application in java that used GcmTaskService to schedule a service and make HTTP requests in the background with HttpsURLConnection (about every 10 minutes) and if the content changed, it would send a notification to the user. This might not have been the best way to do this, but it worked and that was enough for me.

现在,我想用类似的逻辑在Flutter中重写应用程序.我知道iOS在后台工作方面非常严格,因此我可以在非精确时间(每天1-2次是可以的)提出请求.

Now I want to rewrite the app in Flutter, with similar logic. I know iOS is very strict when it comes to background work so I would be fine with the request being made at non-exact times (1-2 times a day is OK).

在Flutter中,我正在使用http.get();(获取数据)和http.post();(登录并获取Bearer代码)来获取必要的数据.

In Flutter I am using http.get(); (get data) and http.post(); (login and get Bearer code) to get the necessary data.

不幸的是,我仅在FCM和推送通知中找到了有关此主题的教程. 由于我无权访问服务器后端,因此暂时无法实现推送通知.

Unfortunately I only found tutorials on this topic with FCM and push notifications. Implementing push notifications is not an option for now, since I was given no access to the server backend.

是否有另一种方法可以通过对API的简单HTTP请求来实现此目的?

Is there another way to do this with simple HTTP requests to the API?

此处是Java中的旧实现.

Here is the old implementation in Java.

推荐答案

我认为 background_fetch 是你想要的.但是,如果您打算支持iOS,则需要小心-在此处此处.

这篇关于如何在Flutter中通过HTTP api从后台发送通知(无推送通知)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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