fluttertpc_headset_connection_event:基于 Flutter 的耳机连接事件监听插件项目

Flutter 耳机事件插件。检测耳机是否插入或拔出。获取当前耳机状态

Branch2Tags7
FilesLast commitLast update
1 year ago
1 year ago
9 months ago
5 years ago
1 year ago
10 months ago
1 year ago
7 years ago
5 years ago
5 years ago
1 year ago
6 years ago
9 months ago
9 months ago
9 months ago
1 year ago
1 year ago
9 months ago
1 year ago
10 months ago

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 following:

HeadsetPlugin.requestPermission();

Introduction

Flutter 耳机事件插件。检测耳机是否插入或拔出。获取当前耳机状态

Customize your domain