Skip to content
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

Fix android patterns #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

crimesp
Copy link

@crimesp crimesp commented Aug 2, 2024

Advanced vibrations weren't working on old android sdk.

I discovered the first value in the patterns needs to be zero

https://developer.android.com/reference/android/os/Vibrator#vibrate(long,%20android.media.AudioAttributes)

Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.

First commit is me getting the android project working in my id
second commit is the actual code change

@nohli
Copy link
Owner

nohli commented Aug 29, 2024

Hi @crimesp

Thanks for opening this PR 😊
Good find! 🙏🏽

What Flutter version are you using? I see some downgrades. I doubt we need the first commit's changes, as I recreated the Android folders recently. By the way, did you manually change single to double quotes, or is there a trick during flutter create? 😊

Concerning the second commit - this seems to break the vibration on devices >= Android 8. What about this change in line 51 instead?

        // https://developer.android.com/reference/android/os/Vibrator#vibrate(long[],%20int)
        val zeroDelay = longArrayOf(0)
        val lengthsWithZeroDelay = zeroDelay + pattern.lengths
        vibrator.vibrate(lengthsWithZeroDelay, -1)

@crimesp
Copy link
Author

crimesp commented Nov 14, 2024

hi nohli, Sorry at the late response - i have only just spotted this reply!

single to double quotes was just part of the delete and recreate on linux ;
flutter create --template=app --platforms android

im on flutter 3.23.3

re your suggestion, yes that seems much cleaner!

apologies for the break in code!

do you want to tweak your suggestion in, or shall i raise a fresh PR?

@nohli
Copy link
Owner

nohli commented Nov 14, 2024

No worries

It would be nice to push here or open a new PR, then you can take credit for finding the bug 🤗

Also, in case you like testing and have an Android device, it would be good to hear more opinions about the other PR from the community regarding Android/iOS similarities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants