How to change incoming call Vibration level when incoming call made?
Asked Answered
M

2

2

Somehow tricky question. I am working with one app through which user can set incoming call custom ringtone and different vibration level for different contacts.

I have stuck with vibration level setting. We can set vibration level using,

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);  

// 1. Vibrate for 1000 milliseconds  
long milliseconds = 1000;  
v.vibrate(milliseconds);  

// 2. Vibrate in a Pattern with 500ms on, 500ms off for 5 times  
long[] pattern = { 500, 300 };  
v.vibrate(pattern, 5);

This is what about vibrate my phone. But I want to set vibration level of incoming call. User can set from different predefined vibration settings.

Using this code I can set Vibration ON - OFF. But dont know how to set level of vibration.

 String VIBRATE_IN_SILENT_SETTING_NAME = "vibrate_in_silent";
Settings.System.putInt(getContentResolver(), VIBRATE_IN_SILENT_SETTING_NAME, 1);

I hope that someone could give some advice on this issue. suggestions are welcomed.

Mimas answered 7/11, 2014 at 15:47 Comment(2)
did the code worked for you?Jargonize
@JordiCastilla Nop. I could not get success. If you find any luck, then you can share.Mimas
C
0

The Android Vibrate API has only time control. There is no magnitude control in that API.

For more refer this

http://developer.android.com/reference/android/os/Vibrator.html

Crocus answered 7/11, 2014 at 18:13 Comment(0)
J
0

If you want to make lower vibration you need to create a pattern with blankspaces in the middle.

Use constants like:

int dot = 200;      
int short_gap = 200;    // Length of Gap 

and then define array and pattern:

long[] pattern = {
    0,  // Start immediately
    dot, short_gap };

then you can call:

v.vibrate(pattern, x);

// x value:
// 0 repeat infinite
// -1 no repeat
// n number of repetitions

By changing lenght of the dot and gap (or defining new ones to perform various patterns) you can modulate power of vibration.

EDIT1: Here is my VibrationConstants.java

public class VibrationConstants {                         

    private static int p = 5; // five millisecond of vibration
    private static int s = 5; // five millisecond of break - could be more to
                  // weaken
                  // the vibration
    private static int pp = 10; // ten millisecond of vibration
    private static int ss = 10; // ten millisecond of break - could be more to
                // weaken
                // the vibration
    private static int ppp = 50; // fifty millisecond of vibration
    private static int sss = 50; // fifty millisecond of break - could be more to
                 // weaken
                 // the vibration

    public static long[] HARD_VIBRATION = { 0, ppp, sss };
    public static long[] MIDDLE_VIBRATION = { 0, pp, ss };
    public static long[] SOFT_VIBRATION_2 = { 0, p, s };

    public static long[] PATTERN_VIBRATION = { 0, 250, 200, 250, 150, 150, 75,
        150, 75, 150 }; 
}

So, when you want to call it:

v.vibrate(VibrationConstants.SOFT_VIBRATION_2, x);

// x value:
// 0 repeat infinite
// -1 no repeat
// n number of repetitions

Try also by changing ONLY the break values if the result with same values in vibration and breaks is not accurated as you expect. This make nice effects. :)

Hope that helps, i tried to found patterns from phone brands like Google Samsung or Xperia, but i couldnt find it... so we had nice results with that patterns to simulate, but all depends of your requirements.

Im sure you will have to make some tests to reach ur target, but is not so hard.

Jargonize answered 8/11, 2014 at 16:19 Comment(4)
You didnt get my question properly. I want to set level of vibration in incoming call.Mimas
I think yes. But you cannot set vibration level cause there is no option for that. I faced that problem in the past, and only solution I found that worked was simulating it by patterns.Jargonize
Yeh. I have tried to vibrate phone like this, but phone is not performing as per our need. Can you please share some code with incoming call receiver if possible ? It will help a lot.Mimas
Not working buddy. I think its not possible to vibrate phone in custom way at the time of incoming call.Mimas

© 2022 - 2025 — McMap. All rights reserved.