Search packages, repositories and app categories

Package detailsv4.1.0

headset_connection_event

Flutter Plugin for headset events. Detect headset is plugged and unplugged. Get current headset state.

AndroidiOS
30-day downloads
2.2K
Likes
28
Pub points
145

Install package

flutter pub add headset_connection_event

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter plugin that detects when a headset is plugged in or unplugged on Android and iOS devices. It provides real-time updates on the current headset connection state, enabling apps to respond dynamically to audio accessory changes. Ideal for media players, voice applications, or any app needing awareness of audio output configuration. The plugin integrates seamlessly with native device APIs through platform channels.

Use cases

  • Media player audio routing
  • Voice assistant input switching
  • Real-time audio device monitoring
  • User experience adaptation based on headset presence
  • Accessibility feature triggering

Key features

  • Real-time headset plug/unplug detection
  • Cross-platform support (Android & iOS)
  • Simple event stream API
  • Current state retrieval
  • Lightweight and minimal dependencies

Suitable for

  • Audio-focused applications
  • Mobile apps requiring hardware interaction
  • Apps needing responsive UI to audio device changes
  • Developers building accessibility tools
  • Flutter projects targeting both Android and iOS

Considerations

  • Requires appropriate permissions on Android
  • Limited to headset connection events only
  • No support for Bluetooth headsets beyond basic detection
  • May require background execution handling on some platforms
  • Dependent on native platform capabilities

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Headset Connection Event Flutter Plugin

A Flutter plugin to get a headset event.

Flutter

This is a clone of headset_event, but with fix on swift errors and bluetooth connection events for Android and iOS

Migrated to AndroidX

Current Status

Platform Physical Headset Bluetooth
iOS ✅ ✅
Android ✅ ✅

Usage

To use this plugin, add headset_connection_event as a dependency in your pubspec.yaml file.

Example
    // Import package
    import 'package:headset_connection_event/headset_event.dart';

    // Instantiate it
    HeadsetEvent headsetPlugin = new HeadsetEvent();
    HeadsetState headsetEvent;

    /// if headset is plugged
    headsetPlugin.getCurrentState.then((_val){
      setState(() {
        headsetEvent = _val;
      });
    });

    /// Detect the moment headset is plugged or unplugged
    headsetPlugin.setListener((_val) {
      setState(() {
        headsetEvent = _val;
      });
    });
Android setup

Update compileSdkVersion to 33 in your build.properties under app directory

Make the following changes to your project's main AndroidManifest.xml file:

<activity...
 <!-- ADD THIS BELOW "ACTIVITY" -->
 android:exported="true"





    <!-- ADD THIS "RECEIVER" Element Before </application> -->
  <receiver android:name="flutter.moum.headset_event.HeadsetBroadcastReceiver"
        android:exported="true">
           <intent-filter>
               <action android:name="android.intent.action.HEADSET_PLUG" />
               <action android:name="android.intent.action.MEDIA_BUTTON" />
           </intent-filter>
       </receiver>


  </application>
</manifest>

Please see example project AndroidManifest.xml for more information.

Android 12 requires bluetoothConnect permission. You may request it using the permission_handler:

Add permission in your manifest

<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
import 'package:permission_handler/permission_handler.dart';

Future<bool> requestPermission() async {
  if (!Platform.isAndroid) return true;
  return Permission.bluetoothConnect.request().isGranted;
}

Categories

Source repository

Projects using this package

No data available yet.