zoukankan      html  css  js  c++  java
  • android 振动

    1.调用Android系统的震动,只需要一个类 那就是Vibrator ,这个类在hard包中,一看系统级的服务,又要通过manifest.xml文件设置权限了

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

    2.代码调用情况

    private Vibrator vibrator;

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

            long [] pattern = {100,400,100,400};   // 停止 开启 停止 开启   

    振动:        vibrator.vibrate(pattern,2);           //重复两次上面的pattern 如果只想震动一次,index设为-1  

    vibrator.vibrate(10);是振动一次

    使用

    取消振动:vibrator.cancel();

    http://blog.csdn.net/xiaocai237/article/details/6669705#

    下面还是一起学习一下SDK吧


    Class that operates the vibrator on the device.
    If your process exits, any vibration you started with will stop.

    //Vibrator类用来操作设备上的震动,如果你的线程退出了,那么启动的震动也会停止

    ---------------------------------------------------------------------------------------------------------------------------------------------------
    public void vibrate (long[] pattern, int repeat)
    Since: API Level 1

    Vibrate with a given pattern.  //根据给定的节奏震动

    Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
    //传递一个整型数组作为关闭和开启震动的持续时间,以毫秒为单位。第一个值表示等待震动开启的毫秒数,下一个值表示保持震动的毫秒数,这个序列值交替表示震动关闭和开启的毫秒数

    To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or -1 to disable repeating.
    //为了重复的按设定的节奏震动,传递index参数表示重复次数,用-1表示不重复。

    Parameters
    pattern     an array of longs of times for which to turn the vibrator on or off.
    repeat     the index into pattern at which to repeat, or -1 if you don't want to repeat.

  • 相关阅读:
    WebView断网提示
    Android连续点击多次事件的实现
    Android ADB Server启动失败
    Android Studio撤销与SVN的关联
    SVN拉取后撤销,恢复未拉取之前的状态
    如何通过报表单元格右键控制报表跳转到不同链接地址
    如何提高报表的取数性能
    如何实现参数级联查询
    如何实现参数和报表间的联动效果
    如何实现报表直接打印需求
  • 原文地址:https://www.cnblogs.com/xiayexingkong/p/4325887.html
Copyright © 2011-2022 走看看