How to change incoming call Vibration level when incoming call made?

前端 未结 2 469

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

2条回答
  •  有刺的猬
    2021-01-22 13:27

    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.

提交回复
热议问题