패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.0.4

phone_state_background

전화 통화 상태를 처리하고 백그라운드에서 Dart 콜백을 실행하는 플러터 플러그인입니다.

Android
30일 다운로드
208
좋아요
26
Pub 점수
160

패키지 설치

flutter pub add phone_state_background

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

phone_state_background 패키지는 안드로이드용 플러터 플러그인으로 전화 통화 상태를 모니터링하고 앱이 백그라운드에 있을 때도 Dart 콜백을 트리거하도록 설계되었습니다. 앱이 활성적으로 실행 중이 아니어도 들어오는, 나가는 또는 놓친 통화에 대해 사용자 정의 로직을 실행할 수 있게 해줍니다. 이는 통화 기록, 분석 또는 통화 이벤트 중 다른 서비스와 통합하는 데 특히 유용합니다. 이 플러그인은 앱 생명주기 변경 시에도 기능을 유지하기 위해 안드로이드의 브로드캐스트 수신기를 활용합니다.

사용 사례

  • 통화 기록
  • 실시간 통화 모니터링
  • 백그라운드 호출 이벤트 처리
  • 전화 서비스와의 통합
  • 통화 상태 변경에 대한 자동 응답

주요 기능

  • 백그라운드 실행 지원
  • 통화 상태 변경 시 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;
  }
}

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.