パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.0.4

phone_state_background

電話通話状態を処理し、バックグラウンドでDartコールバックを実行するためのFlutterプラグインです。

Android
30日間ダウンロード
208
いいね数
26
Pub ポイント
160

パッケージをインストール

flutter pub add phone_state_background

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

phone_state_background パッケージは、Android 向けの Flutter プラグインで、アプリがバックグラウンドにある場合でも電話通話状態を監視し、Dart コールバックをトリガーするように設計されています。アプリがアクティブに実行されていなくても、着信、発信、または着信拒否の通話を検知してカスタムロジックを実行できるようになります。これは通話ログ記録、分析、または通話イベント中に他のサービスと統合する際に特に役立ちます。このプラグインは、アプリのライフサイクル変更にかかわらず機能を維持するために、Android のブロードキャストレシーバーを利用しています。

用途

  • 通話ログ
  • リアルタイム通話モニタリング
  • バックグラウンドコールイベント処理
  • 通話サービスとの統合
  • 通話状態の変更に対する自動応答

主な機能

  • バックグラウンド実行のサポート
  • 通話状態の変更時のDartコールバック
  • Android専用のプラットフォーム互換性
  • シンプルな API インテグレーション
  • ブロードキャストレシーバーに基づくアーキテクチャ

適している対象

  • 電話アプリを開発する開発者
  • バックグラウンド通話追跡が必要なアプリ
  • 分析ツールを呼び出す
  • サービス指向型モバイルアプリケーション

注意事項

  • Android プラットフォームに限定
  • 適切な Android マニフェスト権限が必要です
  • バッテリーの駆動時間に影響を与える可能性があります
  • 新しいAndroidバージョンにおけるバックグラウンド実行の制約
  • iOS 対応なし

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

phone_state_background

A flutter plugin to handle Phone Call State and execute a Dart callback in background.

Warning

This plugin only supported in android platform.


IOS Implementation

Corrently IOS is not supported. Unfortunately I'm not familiar with IOS development neither with Switf/ObjC languages, so if you wish to help any PR will be welcome.


Android

After importing this plugin to your project as usual, add the following to your AndroidManifest.xml within the <manifest></manifest> tags:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />

Also, apparently it is necessary to register the broadcast receiver manually, otherwise an error will be throw saying that our receiver does not exist inside the app. Within the <application></application> tags:,

<receiver android:name="me.sodipto.phone_state_background.PhoneStateBackgroundServiceReceiver"
    android:exported="false">
    <intent-filter>
        <action android:name="android.intent.action.PHONE_STATE" />
    </intent-filter>
</receiver>

Getting started

All you need to start using our package after installing it, is defining a callback which must be a top level function or static function, that will be called by our plugin when any incoming or outgoing call events are detected.

@pragma('vm:entry-point') // Be sure to annotate your callback function to avoid issues in release mode on Flutter >= 3.3.0 void phoneStateBackgroundCallbackHandler(PhoneStateBackgroundEvent event, String number, int duration)

This callback handler must accept 3 arguments:

  • phoneStateBackgroundEvent: The event type detect by our plugin in background.

  • number: The incoming/outgoin number that is triggering the phone state call.

  • duration: An integer that represents the duration of the call in seconds.

The PhoneStateBackgroundEvent is an enum with four possible values:

Event Value Description
incomingstart Indicates an incoming call.
incomingmissed Indicates an incoming call missed.
incomingreceived Indicates an incoming call received.
incomingend Indicates an incoming call end.
outgoingstart Indicates an outgoing call start.
outgoingend Indicates an outgoing call end.

Since all this process happens in background in a Dart Isolate, there's no guarantee that the current OS will call the registered callback as soon as an event is triggered or that the callback will ever be called at all, each OS handle background services with different policies. Make sure to ask user permission before calling the PhoneStateBackground.initialize method of our plugin. Check the example to see a simple implementation of it.

/// Defines a callback that will handle all background incoming events
@pragma('vm:entry-point') // Be sure to annotate your callback function to avoid issues in release mode on Flutter >= 3.3.0
Future<void> phoneStateBackgroundCallbackHandler(
  PhoneStateBackgroundEvent event,
  String number,
  int duration,
) async {
  switch (event) {
    case PhoneStateBackgroundEvent.incomingstart:
      print('Incoming call start, number: $number, duration: $duration s');
      break;
    case PhoneStateBackgroundEvent.incomingmissed:
      print('Incoming call missed, number: $number, duration: $duration s');
      break;
    case PhoneStateBackgroundEvent.incomingreceived:
      print('Incoming call received, number: $number, duration: $duration s');
      break;
    case PhoneStateBackgroundEvent.incomingend:
      print('Incoming call ended, number: $number, duration $duration s');
      break;
    case PhoneStateBackgroundEvent.outgoingstart:
      print('Ougoing call start, number: $number, duration: $duration s');
      break;
    case PhoneStateBackgroundEvent.outgoingend:
      print('Ougoing call ended, number: $number, duration: $duration s');
      break;
  }
}

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。