Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Notification.DEFAULT_VIBRATE do?

How does Notification.DEFAULT_VIBRATE work? If I set:

notification.defaults |= Notification.DEFAULT_VIBRATE;

what's going to happen?

The documentation is not clear. How can I make the phone vibrating if and only if the vibrate-option for the native sms application or for the call is set to true?

like image 945
kingston Avatar asked Dec 20 '25 16:12

kingston


1 Answers

You need to add following permition for enabling vibrate.

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

And for detecting vibrate mode you can use AudioManager's getRingerMode() method

    AudioManager audiomanager = (AudioManager)
                                getSystemService(Context.AUDIO_SERVICE);

    switch (audiomanager.getRingerMode()) {
        case AudioManager.RINGER_MODE_SILENT:
            Log.i("Mode","Silent mode");
            break;
        case AudioManager.RINGER_MODE_VIBRATE:
            Log.i("Mode","Vibrate mode");
            break;
        case AudioManager.RINGER_MODE_NORMAL:
            Log.i("Mode","Normal mode");
            break;
    }

EDIT

You can check user's vibrate settings of call and notification using following code

Log.i("Setting", ""+audiomanager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER));
Log.i("Setting", ""+audiomanager.shouldVibrate(AudioManager.VIBRATE_TYPE_NOTIFICATION));
like image 103
Mihir Palkhiwala Avatar answered Dec 23 '25 05:12

Mihir Palkhiwala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!