안드로이드 및 iOS 기기에서 헤드셋이 꽂히거나 빠졌을 때를 감지하는 플러터 플러그인입니다. 현재 헤드셋 연결 상태에 대한 실시간 업데이트를 제공하여 앱이 오디오 액세서리 변경에 동적으로 반응할 수 있게 해줍니다. 미디어 플레이어, 음성 애플리케이션 또는 오디오 출력 구성에 대한 인식이 필요한 모든 앱에 적합합니다. 플러그인은 플랫폼 채널을 통해 네이티브 장치 API와 원활하게 통합됩니다.
사용 사례
미디어 플레이어 오디오 라우팅
음성 보조 입력 전환
실시간 오디오 장치 모니터링
헤드셋 존재에 따른 사용자 경험 적응
접근성 기능 트리거
주요 기능
실시간 헤드셋 플러그/언플러그 감지
크로스 플랫폼 지원 (Android 및 iOS)
간단한 이벤트 스트림 API
현재 상태 검색
경량이며 최소한의 종속성
적합한 대상
오디오 중심 애플리케이션
하드웨어 상호작용을 요구하는 모바일 앱
오디오 장치 변경에 반응하는 UI가 필요한 앱
접근성 도구를 개발하는 개발자
Android 및 iOS를 대상으로 하는 Flutter 프로젝트
고려 사항
Android에서 적절한 권한이 필요합니다
헤드셋 연결 이벤트에만 제한됨
기본 탐지 기능을 초과한 블루투스 헤드셋에 대한 지원 없음
일부 플랫폼에서는 백그라운드 실행 처리가 필요할 수 있습니다
네이티브 플랫폼 기능에 의존
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Headset Connection Event Flutter Plugin
A Flutter plugin to get a headset event.
This is a clone of headset_event, but with fix on swift errors and bluetooth connection events for Android and iOS
// Import packageimport'package:headset_connection_event/headset_event.dart';
// Instantiate itHeadsetEvent headsetPlugin = newHeadsetEvent();
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...
<!--ADDTHISBELOW "ACTIVITY" -->
android:exported="true"
<!-- ADD THIS "RECEIVER" Element Before </application> --><receiverandroid:name="flutter.moum.headset_event.HeadsetBroadcastReceiver"android:exported="true"><intent-filter><actionandroid:name="android.intent.action.HEADSET_PLUG" /><actionandroid: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: