【问题标题】:How to change incoming call Vibration level when incoming call made?来电时如何更改来电振动级别?
【发布时间】:2014-11-07 15:47:18
【问题描述】:

有点棘手的问题。我正在使用一个应用程序,用户可以通过它为不同的联系人设置来电自定义铃声和不同的振动级别。

我一直坚持振动级别设置。我们可以设置振动级别使用,

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);

这就是振动我的手机的方法。但我想设置来电的振动级别。用户可以从不同的预定义振动设置中进行设置。

使用此代码,我可以将振动设置为 ON - OFF。但不知道如何设置振动水平。

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

我希望有人可以就这个问题提供一些建议。欢迎提出建议。

【问题讨论】:

  • 代码对你有用吗?
  • @JordiCastilla Nop。我无法获得成功。如果你发现任何运气,那么你可以分享。

标签: android android-vibration incoming-call


【解决方案1】:

Android Vibrate API 只有时间控制。该 API 中没有幅度控制。

更多信息请参考this

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

【讨论】:

    【解决方案2】:

    如果你想降低振动,你需要创建一个中间有空格的图案。

    使用如下常量:

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

    然后定义数组和模式:

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

    然后你可以调用:

    v.vibrate(pattern, x);
    
    // x value:
    // 0 repeat infinite
    // -1 no repeat
    // n number of repetitions
    

    通过改变点和间隙的长度(或定义新的点和间隙来执行各种模式),您可以调节振动的力量。

    EDIT1:这是我的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 }; 
    }
    

    所以,当你想调用它时:

    v.vibrate(VibrationConstants.SOFT_VIBRATION_2, x);
    
    // x value:
    // 0 repeat infinite
    // -1 no repeat
    // n number of repetitions
    

    如果在振动和断裂中具有相同值的结果不符合您的预期,请尝试仅更改断裂值。这会产生很好的效果。 :)

    希望对您有所帮助,我尝试从谷歌三星或 Xperia 等手机品牌中找到模式,但我找不到......所以我们用这些模式模拟了很好的结果,但这一切都取决于您的要求。

    我相信你必须做一些测试才能达到你的目标,但这并不难。

    【讨论】:

    • 你没有正确理解我的问题。我想在来电中设置振动级别。
    • 我认为是的。但是您不能设置振动级别,因为没有选项。我过去遇到过这个问题,我发现唯一可行的解​​决方案是通过模式来模拟它。
    • 是的。我曾尝试像这样振动手机,但手机没有按照我们的需要运行。如果可能的话,您能否与来电接收者分享一些代码?会有很大帮助的。
    • 不工作的伙伴。我认为来电时无法以自定义方式振动手机。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    相关资源
    最近更新 更多