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

Vibrate doesn't work in android and ios #3702

Open
DurankGts opened this issue May 4, 2023 · 13 comments
Open

Vibrate doesn't work in android and ios #3702

DurankGts opened this issue May 4, 2023 · 13 comments
Assignees
Labels
good first issue Good for getting started Hacktoberfest Suitable for new contributor. Part of Hacktoberfest your-first-pr Make your first pull request

Comments

@DurankGts
Copy link
Contributor

Display.getInstance().vibrate(1000);

why this code doesn't work?

@DurankGts
Copy link
Contributor Author

DurankGts commented May 4, 2023

I just add this to
codename1.arg.android.xpermissions = <uses-permission android:name="android.permission.VIBRATE" />

and it actually work in android 11 but not in ios.

Any support about this?

@shai-almog shai-almog added good first issue Good for getting started Hacktoberfest Suitable for new contributor. Part of Hacktoberfest your-first-pr Make your first pull request labels May 5, 2023
@shai-almog
Copy link
Collaborator

shai-almog commented May 5, 2023

It seems the code here should be updated based on this.

On iOS there's no guarantee vibrate will work as mentioned here. Relevant paragraph:

On some iOS devices, you can pass the kSystemSoundID_Vibrate constant to invoke vibration. On other iOS devices, calling this function with that constant does nothing.

This applies to this code.

So this should only be fixed for Android only as far as I can tell.

@regulas1
Copy link

Hi There May I take This Up ? I am new to Open Source so I want to try this one.
Please let me know if it good for me to work with?

@shai-almog
Copy link
Collaborator

Sure @regulas1
assigned the issue to you.

@regulas1
Copy link

regulas1 commented May 28, 2023

Hi @shai-almog can you check if the code below is the correct fix ?

Replaced this
v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
With this
val v: Vibrator = (getSystemService(Context.VIBRATOR_SERVICE) as? VibratorManager)?.defaultVibrator ?: (getSystemService(Context.VIBRATOR_SERVICE) as Vibrator)

@shai-almog
Copy link
Collaborator

The second code is in Kotlin, not Java. So no it isn't correct. You need to adapt the Kotlin syntax to Java.
We only support Java 6 level syntax at the moment so you can't even use current syntax levels.

@regulas1
Copy link

regulas1 commented May 29, 2023

Apologies.
may you please let me know if this is the fix?
Vibrator v; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { VibratorManager vibratorManager = (VibratorManager) getSystemService("vibrator_manager"); v = vibratorManager.getDefaultVibrator(); } else { v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); }

@shai-almog
Copy link
Collaborator

I can't compile things in my head. I suggest making the changes and trying to compile them. The easiest way is to create a test application, generate a native Android project from that and try to debug this in Android Studio.

The code you included assumes this is an Activity but in Codename One our activity is typically a separate class from the implementation where this code resides. So you would need to make some changes to that code.

@regulas1
Copy link

makes sense thanks for the great help

@u7484052
Copy link

Hi, apologies if I'm missing something obvious but it appears that no PRs have been made regarding this issue and therefore I am wondering if it is still up for grabs as I need an issue for a Uni assignment. It appears to be a pretty simple fix which is great looking that I had previously started working on another issue on another project only for them to announce that they would implement a full feature freeze for the whole project while they rewrote the entire repository... And my assignment is due sort of soon lol.

@regulas1
Copy link

Sure you can take over apologies had some issues with getting devices to test on after the change

@shai-almog
Copy link
Collaborator

Based on this question it works and just requires adding the vibrate permission.

@u7484052
Copy link

u7484052 commented Oct 25, 2023

Cool, is the requirement for adding the vibrate permissions client side or can it be globally set within CodenameOne? Also, I have written a simple case statement that checks if the SDK is greater than 31, if it is then it uses the new vibrate manager and if not it uses the existing code. Just some simple retro-comparability that I thought wouldn’t hurt to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for getting started Hacktoberfest Suitable for new contributor. Part of Hacktoberfest your-first-pr Make your first pull request
Projects
None yet
Development

No branches or pull requests

4 participants