标签:

android

vibrator

震动器

it

分类: Andorid

获取振动器Vibrator实例:

Vibrator  mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
Vibrator.vibrate()方法:

只有1个参数的时候,第一个参数用来指定振动的毫秒数。

要传递2个参数的时候,第1个参数用来指定振动时间的样本,第2个参数用来指定是否需要循环。 
振动时间的样本是指振动时间和等待时间的交互指定的数组。
 

※下面的例子,在程序起动后等待3秒后,振动1秒,再等待2秒后,振动5秒,再等待3秒后,振动1秒
 
      long[] pattern = {3000, 1000, 2000, 5000, 3000, 1000}; //
OFF/ON/OFF/ON…

需要在AndroidManifest.xml里进行下类设定
<uses-permission
android:name=”android.permission.VIBRATE”/>

例程源码(Java)
public
class VibratorTestActivity extends Activity {
 
 
 
  @Override
 
  public void onCreate(Bundle savedInstanceState) {
 
      super.onCreate(savedInstanceState);
 
      setContentView(R.layout.main);
 
      Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

long[] pattern = {3000, 1000, 2000, 5000, 3000, 1000}; //
OFF/ON/OFF/ON

vibrator.vibrate(pattern, -1);

}

@Override
 
  public boolean onTouchEvent(MotionEvent event) {
 
      if (event.getAction() == MotionEvent.ACTION_MOVE) {
 
          Vibrator vibrator = (Vibrator)
getSystemService(VIBRATOR_SERVICE);
 
          vibrator.vibrate(10);
 
      }
 
      return super.onTouchEvent(event);

Andorid手机振动器(Vibrator)的使用的更多相关文章

  1. Android中振动器(Vibrator)的使用

    系统获取Vibrator也是调用Context的getSystemService方法,接下来就可以调用Vibrator的方法控制手机振动了.Vibrator只有三个方法控制手机振动: 1.vibrat ...

  2. andorid 手机外部储存

    .xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  3. andorid手机电脑操作

    之前一直使用androidscreencast在pc上对手机进行操作,好久都没用了,前些天再次用的时候,提演示样例如以下: 决定还是自己写一个吧,由于7月份要做一个小分享,打算讲一些android的东 ...

  4. Andorid 手机WIFI连接的Mac地址和IP地址

    public static String getInfo()     {        WifiManager wifi = (WifiManager) getSystemService(Contex ...

  5. Android 振动器

    今天介绍一下Android的振动器Vibrator,有三个方法来控制手机振动: 1.void vibrate(long milliseconds):控制手机振动milliseconds毫秒. 2.vo ...

  6. [android] 手机卫士输入框抖动和手机震动

    查看apiDemos,找到View/Animation/shake找到对应的动画代码,直接拷贝过来 当导入一个项目的时候,报R文件不存在,很多情况是xml文件出错了 Animation shake = ...

  7. 如何在 Android 手机上实现抓包?

    如何在 Android 手机上实现抓包? http://www.zhihu.com/question/20467503 我想知道某个应用究竟在数据提交到哪里,提交了什么.网上的教程太复杂,不想麻烦.有 ...

  8. Android利用Fiddler进行网络数据抓包,手机抓包工具汇总

    Fiddler抓包工具 Fiddler抓包工具很好用的,它可以干嘛用呢,举个简单例子,当你浏览网页时,网页中有段视频非常好,但网站又不提供下载,用迅雷下载你又找不到下载地址,这个时候,Fiddler抓 ...

  9. 如何管理安卓android手机下google(谷歌)的通讯录联系人账户

    andorid手机都自带通讯录备份功能,但是如何管理,一直是一些人头疼的问题.经常在手机备份还原之后发现很多联系人都有重复. 1.打开 :https://mail.google.com/ 用你的谷歌账 ...

随机推荐

  1. Linux文件系统的barrier:启用还是禁用

    大多数当前流行的Linux文件系统,包括EXT3和EXT4,都将文件系统barrier作为一个增强的安全特性.它保护数据不被写入日记.但 是,在许多情况下,我们并不清楚这些barrier是否有用.本文 ...

  2. angularJs中图表功能(有集成框架)-angular-flot

    1.柱状图和折线图的数据格式: $scope.Chart.data = [ { label: "离线", data: [[0, 2]] }, { label: "在线&q ...

  3. 剑指Offer17 二叉树的镜像

    /************************************************************************* > File Name: 17_Mirror ...

  4. poj 1330 Nearest Common Ancestors 裸的LCA

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...

  5. 真机调试时提示: could not change executable permissions on the application

    原因:同一个bundle identifier不能重复在两个app中使用: 解决:卸载掉手机上的另一个app即可重新安装.

  6. MongoDB - The mongo Shell, mongo Shell Quick Reference

    mongo Shell Command History You can retrieve previous commands issued in the mongo shell with the up ...

  7. ServiceStack简介

    原文:http://bbs.csdn.net/topics/390911450?page=1#post-398388262 在帖子中看到,大致了解了下,非常好的框架,留着学习 https://gith ...

  8. Node.js的安装

    学习一下JavaScript的另一个运行环境---Node.js Node.js是一个基于Chrome V8 引擎的 JavaScript 运行建立的平台, 用于方便地搭建响应速度快.易于扩展并且是全 ...

  9. php 读写xml 修改xml

    需要修改的xml <?xml version="1.0"?> <config> <administration> <adminuser&g ...

  10. server——小记

    问题 Step 1   Start the server in Directory Services Restore Mode   Windows Server 2003/2008 Directory ...