-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Does not work when targetSdkVersion is set to 31+ #8
Comments
The problem is that, after setting TargetSdk to 31+, you have to request permissions for bluetoothconnect. This requires the user agreeing to a prompt. See my fork here: https://github.com/Colton127/headset_connection_event I discovered a different way of detecting headset status, including listening to events, by using https://github.com/ryanheise/audio_session. session.getDevices returns currently connected devices, and session.devicesChangedEventStream will listen to changes. You have to then create a function that determines if the device is a headset or not. I'll leave this open while I continue my research. I should be pulling my fork soon. |
Wow awesome catch @Colton127 - I was wondering why a few months ago my app stopped working when I did seemingly minor version bumps, thanks for the fork, will use it 👍 |
Thank you, and you're welcome. I actually used your fork earlier in attempt to fix the problem but had no luck. I have a HeadPhone manager class that utilizes audio_session and doesn't require any annoying permissions. I may publish it once I verify it works 100%. Until then, Google is out to annoy us! |
@Colton127 awesome fork mate! Apologies for not updating this project anymore. Feel free to publish your fork/library in pub.dev and I'll link yours from here so users can start using that. Or you can raise a PR here for that fork and ill merge it. Cheers |
Haha apologies about my fork not working - I had it working locally but when I tried to integrate my plugin with my actual app it was crashing (and didn't revisit the plugin) - would be absolutely curious with your Update - nice, the devices changed stream is perfect, I just did something really hacky and quick:
but depending if you wanted bluetooth specific you could easily do payload.devicesRemoved.any((device) => isBlueTooth(device)) with checks on the bluetooth type. I imagine @Colton127 that is what you ended up with doing |
I have merged your PR #11 and published it as part of the latest release @Colton127 🙏 |
@Colton127 @themobilecoder
So looking at the PR we still have to request permission for Android 12+? |
Hi @Heech! It seems like this specific Bluetooth functionality that we use (
So I'm not sure if there's a way to circumvent this |
@themobilecoder |
@Heech mate that's a really good point. So the permission that we use in this repo is Looking at Youtube, like you said, no such permission. I got curious and found this stackoverflow thread, and looks like there's a way to capture this event without ever needing bluetooth permission. (Use AudioManager) Only thing here is that it does not use |
To replicate: Open example, change targetSdkVersion to 31 (or 32) in build.gradle, make the necessary changes in AndroidManifest, and build.
You will have to make these minor adjustments in AndroidManifest
Under "<activity
android:exported="true"
And make this the intent-filter
This will allow you to successfully build the release onto your device. However, the listener does not work at all. It simply does not respond to bluetooth connect/disconnect events. Setting TargetSdkVersion to 30, even while keeping the above manifest changes, fixes the problem entirely. This is on an Android 12 device.
The text was updated successfully, but these errors were encountered: