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

套件詳情v0.8.0

flutter_foreground_plugin

一個用於 Flutter 的前景服務外掛。僅支援 Android(支援 Oreo)。iOS 目前尚未支援。

Android
近 30 天下載
280
喜歡數
52
Pub 分數
150

安裝套件

flutter pub add flutter_foreground_plugin

套件介紹

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

一個 Flutter 插件,可在 Android 上啟用前臺服務功能,特別支援 Android Oreo 及以上版本。它允許應用在背景執行任務並顯示持續通知,確保即使應用不在前景也能持續運作。此插件專為需要長時間運行操作的場景設計,例如定位追蹤、音樂播放或檔案下載。目前不支援 iOS。它與 Flutter 的平台通道無縫整合,並提供簡單的 API 來啟動和停止前臺服務。

適用情境

  • 背景位置追蹤
  • 長時間執行的檔案下載
  • 背景音樂播放
  • 即時資料同步
  • 持續任務執行

主要特色

  • 僅限 Android Oreo 及以上版本
  • 持續的前臺通知
  • 簡單的啟動/停止 API
  • 平台通道整合
  • 無 iOS 支援

適合對象

  • 需要持續背景執行的應用程式
  • 基於位置的服務
  • 媒體播放器
  • 任務排程器
  • 背景資料處理

使用建議

  • 與 iOS 不相容
  • 需要 Android Oreo 或更高版本
  • 必須顯示一個持續通知
  • 僅限 Android 平台
  • 可能影響電池壽命

原始 README

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

flutter_foreground_service_plugin

You Can Do this plugin with..

  • Start Foreground Service (with callback)
  • Stop Foreground Service (with callback)
  • Using infinite interval on your configurations
  • Change Notification title and contents

You Can Not Do this plugin with...

  • [ ] Change Notification Level

If you use this plugin.

  1. Add dependency to your pubspec.yaml
dependencies:
    ...

  flutter_foreground_plugin: ^0.4.0
  1. Add permission for ForegroundService to AndroidManifest.xml
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
  1. Add service for ForegroundService to AndroidManifest.xml below </activity>
<service android:name="changjoopark.com.flutter_foreground_plugin.FlutterForegroundService"/>
  1. Add use-sdk under application
    <uses-sdk
        android:minSdkVersion="23"
        tools:overrideLibrary="changjoopark.com.flutter_foreground_plugin" />
  1. Add icon image for notification.

Notification Icon Generator will be helpful.

path: android/app/src/main/res/drawable-*

  1. Write code for foreground service
void main() {
  runApp(MyApp());
  startForegroundService();

  // if you need to stop foreground service,
  // await FlutterForegroundPlugin.stopForegroundService();
}

void startForegroundService() async {
  await FlutterForegroundPlugin.setServiceMethodInterval(seconds: 5);
  await FlutterForegroundPlugin.setServiceMethod(globalForegroundService);
  await FlutterForegroundPlugin.startForegroundService(
    holdWakeLock: false,
    onStarted: () {
      print("Foreground on Started");
    },
    onStopped: () {
      print("Foreground on Stopped");
    },
    title: "Flutter Foreground Service",
    content: "This is Content",
    iconName: "ic_stat_hot_tub",
  );
}

void globalForegroundService() {
  debugPrint("current datetime is ${DateTime.now()}");
}

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。