Android: Enable Haptic Feedback and Keypress Sound

I have a problem with the system settings in Android. In short, we are developing an application that does some custom experiments using different input parameters. We will need to enable and disable keystroke sounds and keystroke vibrations programmatically in different experiments.

I've explored a few options, but would like to avoid actually manually tuning the listener and vibration, if at all possible.

I gave myself permission to change system settings:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

      

Below is the code I am using to change system settings:

   android.provider.Settings.System.putInt(getContentResolver(),
             android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED,
             1);

      

Changes are not reflected in the system settings.

The following code works, confirmed by the fact that the settings are actually changed in the system settings window on the emulator.

   android.provider.Settings.System.putInt(getContentResolver(),
             android.provider.Settings.System.TEXT_AUTO_PUNCTUATE,
             0);

   android.provider.Settings.System.putInt(getContentResolver(),
             android.provider.Settings.System.TEXT_AUTO_REPLACE,
             0);

      

I also tried to set specific preferences in the view, as such:

    EditText inputArea = (EditText) findViewById(R.id.editText1);
    inputArea.setHapticFeedbackEnabled(true);
    inputArea.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
    inputArea.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);

      

I pushed him to the phone and it has no effect either.

What I need is a way to programmatically enable / disable haptic feedback and sound on key presses during the experiment. I searched for Stack Overflow but didn't find anything useful.

Does anyone know any tricks or will I have to override myself with key handlers and manually vibrate the phone?

Thank!

+3
java android dalvik


source to share


No one has answered this question yet

Check out similar questions:

nine
Android: Changed to quiet ringer mode does not stop phone vibration
7
Android: Haptic feedback: onClick () event versus hapticFeedbackEnabled in view
4
How to mute physical sound (sound effects) in android app?
3
Detect if phone vibrates on physical / software device
2
Android Vibration API
2
Vaguely about haptic feedback in Android
1
Where is the VibrateSetting (AudioManager.VIBRATE_TYPE_NOTIFICATION, false) set in the phone?
0
How to get click events in JavaScript on long press in Android WebView?
0
Enable sound selection in settings
0
How do I enable tactical feedback (vibration) in WebView?



All Articles
Loading...
X
Show
Funny
Dev
Pics