Android Vibration APIs

I am experimenting with sound manager application to create different sound profiles for "RING, NOTIFICATION, MEDIA, SYSTEM".

As per setting the volume level, I am succeeded with it by using

AudioManager setStreamVolume(AudioManager.STREAM_RING, <value>);

The challenge comes with Vibration Settings.

Currently the api call:

AudioManager setVibrateSetting(vibrateType, vibrateSetting);

Is deprecated in API level 16 and no hope to use it..

The other alternatives is to use

AudioManager setRingerMode(AudioManager.RINGER_MODE_NORMAL);

But I am precisely looking to turn off and turn on vibration for


from my custom application. Or turn on for one of them at any time.

You can think I am doing something similar to the enabling and disabling vibration in sound settings from the OS settings option.

Any help?


Try this:

audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);

For your concern firstly you need to define in Manifest file like this

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

And use like this in your class file. Wonder where exactly you need to put this.

// You need to define some sort of pattern for this
    Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = {0, 1000, 0};
    //long[] pattern = {startTime, TotalTimeDuration, not vibrating for 0ms}; .. Example for above stuff
    vb.vibrate(pattern, 0);

For Example:

button.setOnTouchListener(new OnTouchListener() {
    Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                long[] pattern = {0, 1000, 0};
                vb.vibrate(pattern, 0);
            case MotionEvent.ACTION_UP:
        return false;

Need Your Help

Available UserConfigurationName names for GetUserConfiguration for DistinguishedFolderId 'calendar'?

exchange-server exchangewebservices

The Exchange Web Services have a method GetUserConfiguration that needs a UserConfigurationName to determine what settings to retrieve for a folder.

GDB core dump: Find executable by build-id

linux debugging gdb core coredump

Is it possible to make gdb automatically find the corresponding executable file? I have extracted the debug symbols and put them in the /usr/lib/debug/.build-id/ directory. When I start gdb with gdb

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.