搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.1+1

foreground_service

用於透過 Android 前台服務執行 Dart 程式碼的 Flutter 外掛。僅在 Android O 上進行了基本測試,M 版本上略作測試。不計畫支援 iOS。

近 30 天下載
25
喜歡數
52
Pub 分數
30

安裝套件

flutter pub add foreground_service

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,讓 Dart 程式碼能在 Android 前景服務中執行,確保長時間運行的任務即使應用程式處於背景時也能持續進行。主要針對 Android O 及更新版本設計,舊版本測試較少。不計畫支援 iOS。此外,該插件與 Android 的前景服務生命週期整合,讓應用程式能維持關鍵作業,例如定位追蹤或音訊播放,而不會被系統終止。需在 Android 清單中正確設定與權限。

適用情境

  • 背景位置追蹤
  • 長時間運行的數據處理
  • 後台音頻播放
  • 持久的網絡連接
  • 即時監控服務

主要特色

  • Android 前台服務整合
  • Dart程式碼在前景上下文中執行
  • 系統級持久化
  • 最小 iOS 支持
  • 需要配置清單

適合對象

  • 需要背景任務可靠性的應用
  • 基於位置的服務
  • 媒體播放器
  • 物聯網裝置控制器
  • 即時資料同步

使用建議

  • 無 iOS 支援
  • 在較舊的 Android 版本上進行了有限測試
  • 需要 Android 清單設定
  • 需要前臺服務通知
  • 電池使用影響

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

foreground_service (Flutter v.1.12.x or later)

Create Android foreground service/notification

Prep (Android side):

Android foreground services require a notification to be displayed,
and notifications require an icon.

For this plugin to work, the icon needs to be in this specific location:

res/drawable/org_thebus_foregroundserviceplugin_notificationicon

(take a look at the /example app if you're confused)


-- NOTE FOR PLUGIN VERSION 2.0.0 and above --
compileSdkVersion & targetSdkVersion need to be 29 or above, or the build will fail
these values are set/can be changed in the build.gradle for the app

Use (Flutter/Dart side):

To start the service, call ForegroundService.startForegroundService([serviceFunction])

serviceFunction will then be executed periodically, but "minimum/best-effort"
i.e. it will try to make the interval between function executions *at least* that long

Doesn't work?

As long as you're calling ForegroundService.startForegroundService,
"flutter run" should show error messages that indicate what's wrong/missing

i.e. messages beginning with E/ForegroundServicePlugin indicate an error from the plugin

Caution:

ForegroundService.notification.get* methods may give unexpected values.

Once notifications are sent out, there's no way to retrieve the "current" data.

To work around this, the plugin keeps a version of the notification around.
This version may not have been "sent out" yet, however.

Disclaimer:

Most of the fancy stuff is shamelessly pilfered from the android_alarm_manager plugin

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。