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

Implemented API 31+ vibration service code to replace depreciated code #3755

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import android.media.AudioManager;
import android.net.Uri;
import android.os.Vibrator;
import android.os.VibratorManager;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
Expand Down Expand Up @@ -2610,9 +2611,20 @@ public int getSoftkeyCount() {
public void vibrate(int duration) {
if (!this.vibrateInitialized) {
try {
v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
/**
* Implementation takes into account for retrocompatability if the
* SDK ever needs to be reverted to pre 31 for some reason?
*/
if (Build.VERSION.SDK_INT >= 31) {
// SDK >= 31
VibratorManager vibratorManager = (VibratorManager) getSystemService(Context.VIBRATOR_MANAGER_SERVICE);
v = vibratorManager.getDefaultVibrator();
} else {
// Backward compatability for SDK < 31
v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
}
} catch (Throwable e) {
Log.e("Codename One", "problem with virbrator(0)", e);
Log.e("Codename One", "problem with vibrator(0)", e);
} finally {
this.vibrateInitialized = true;
}
Expand Down
Loading