如何更改来电振动水平时,来电做? [英] How to change incoming call Vibration level when incoming call made?

查看:224
本文介绍了如何更改来电振动水平时,来电做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知何故棘手的问题。我正与一个应用程序,用户可以通过设置来电自定义铃声和不同的振动水平不同的联系人。

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

这是关于什么的震动我的手机。但我想设置来电振动水平。用户可以设置不同predefined振动设置。

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.

使用这个code我可以设置振动开 - 关。但不知道如何设置振动水平。

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. Thanks in advanced.

推荐答案

如果你想较低的振动,你需要创建中间blankspaces的模式。

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

使用常数这样的:

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

也尝试如果结果与振动和休息的价值观,你想到的是不是accurated改变只有分隔值。这使得好的效果。 :)

希望帮助,我试图从手机品牌像谷歌或三星的Xperia发现模式,但我不能找到它......所以我们不得不与模式模拟不错的结果,但一切都取决于你的需求。

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.

这篇关于如何更改来电振动水平时,来电做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆