搜索插件、代码仓与 APP 分类

phone_state 封面
插件详情v4.0.1

phone_state

此插件可让您快速且轻松地了解您的 Android 或 iOS 设备是否正在接收来电,以及通话状态。

AndroidiOS
近 30 天下载
1.5万
喜欢数
141
Pub 分数
160

安装插件

flutter pub add phone_state

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

phone_state 包提供了一种简单的方法,用于在 Android 和 iOS 设备上检测来电并监控通话状态。该插件使应用程序能够在接收到电话时动态响应,例如暂停媒体播放或调整应用行为。该插件利用原生设备 API 实现实时通话状态更新,设置简单。它非常适合需要感知电话事件的应用程序,如音乐播放器、消息应用或需要在通话期间进行调整的生产力工具。

适合场景

  • 检测来电
  • 通话期间暂停媒体
  • 调整通话期间的应用行为
  • 实时监控通话状态
  • 与电话感知功能集成

主要特点

  • 实时通话状态检测
  • 跨平台支持(Android 和 iOS)
  • 最小配置
  • 原生 API 集成
  • 轻量且高效

适合对象

  • 媒体播放应用
  • 生产力工具
  • 消息应用
  • 集成电话功能的服务
  • 需要通话事件感知的应用程序

使用建议

  • 两个平台都需要适当的权限
  • 仅限调用状态,无法实现完整的电话控制
  • 可能需要处理后台执行
  • 行为在 Android 和 iOS 之间略有差异
  • 不适用于拨打电话或管理通话

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

DESCRIPTION

This plugin allows you to know quickly and easily if your Android or iOS device is receiving a call and to know the status of the call.

PAY ATTENTION

  • In the iOS simulator doesn't work
  • The caller phone number is only available on Android, not iOS
  • This plugin reports phone call state only. It does not answer, reject, end, or record calls, and it does not change whether other packages can capture call audio.
  • Android detects system telephony call state only. Third-party VoIP calls from apps such as Telegram or WhatsApp are not supported. iOS CallKit behavior can differ by app.
  • The iOS implementation uses CallKit. For apps distributed in regions where CallKit is restricted, including China App Store review contexts, confirm availability and territory rules with Apple before submission.
  • PhoneState.stream requires the app process to be running with an active Flutter engine and listener. It does not send callbacks after the app is terminated.
  • On Android, if PhoneState.stream does not emit, confirm READ_PHONE_STATE is declared and granted at runtime. Some OEM battery or background restrictions, including MIUI settings on Xiaomi devices, can also delay or block callbacks.

Buy Me A Coffee

HOW TO INSTALL

Flutter

Note: This version requires Flutter >= 3.44.0 and Dart >= 3.12.2. Add phone_state to your app's pubspec.yaml, not to this package's pubspec.yaml. Your app/package name must be different from phone_state.

dependencies:
  flutter:
    sdk: flutter
  phone_state: 4.0.1
Android: Added permission on manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />

READ_PHONE_STATE is required. READ_CALL_LOG is optional and only needed for caller phone numbers.

Warning: Adding READ_CALL_LOG permission, your app will be removed from the Play Store if you don't have a valid reason to use it. Read more.

iOS: Not needed permissions on info.plist

HOW TO USE

Get stream phone state status
StreamBuilder<PhoneState>(
  stream: PhoneState.stream,
  ...
Troubleshooting package conflicts

If phone_state stops receiving updates after adding another package:

  • Confirm the required Android runtime permissions are granted before listening. READ_PHONE_STATE is required, and READ_CALL_LOG is only needed for caller phone numbers.
  • Keep a single active PhoneState.stream listener for each app flow. Cancel the previous subscription before starting another one when screens, services, or background handlers change.
  • When reporting a conflict, include the other package names, platform versions, a minimal reproduction, and the relevant Flutter, Logcat, or Xcode logs.

SCREENSHOT

Write me in the GitHub issues the new features you need and, if they are approved of course, I will implement them as soon as I can.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。