源码如下:

  1. uses
  2. Androidapi.JNI.Os,
  3. Androidapi.JNIBridge;
  4. function GetVibratorArray(const AIntArr: array of Int64): TJavaArray<Int64>;
  5. var
  6. LIndex: Integer;
  7. begin
  8. Result := TJavaArray<Int64>.Create(Length(AIntArr));
  9. for LIndex := Low(AIntArr) to High(AIntArr) do
  10. Result.Items[LIndex] := AIntArr[LIndex];
  11. end;
  12. procedure VibratorTest;
  13. var
  14. LVibratorObj: JObject;
  15. LVibrator: JVibrator;
  16. LJavaArray: TJavaArray<Int64>;
  17. begin
  18. { Vibrator概要:
  19. cancel(): 关闭震动
  20. hasVibrator():检查硬件是否支持
  21. vibrate(long milliseconds): 震动milliseconds毫秒
  22. vibrate(long[] pattern, int repeat):按给定数组震动 }
  23. { 需要开启Vibrator权限 }
  24. // <del>LVibrator := TJVibrator.Create as JVibrator;</del>
  25. { 使用官方推荐方式创建 2014-5-8 update}
  26. LVibratorObj := SharedActivity.getSystemService(
  27. TJContext.JavaClass.VIBRATOR_SERVICE);
  28. LVibrator := TJVibrator.Wrap((LVibratorObj as ILocalObject).GetObjectID);
  29. { 测试手机是否支持震动 }
  30. if not LVibrator.hasVibrator then
  31. begin
  32. ShowMessage('手机不支持震动');
  33. Exit;
  34. end;
  35. { Test procedure vibrate(milliseconds: Int64); cdecl; overload; }
  36. { 效果A: 立即震动 800 毫秒 }
  37. //  LVibrator.vibrate(800);
  38. { Test procedure vibrate(pattern: TJavaArray<Int64>; repeat_: Integer); cdecl; overload;
  39. pattern: 为震动数组参数,偶数代表等待时间(ms), 奇数代表震动持续时间(ms)
  40. repeat_: -1: 只震动一遍;  > -1: 从Index为 repeat_ 的位置开始重复震动 }
  41. { 创建测试数组 }
  42. LJavaArray := GetVibratorArray([500, 1000, 2000, 3000]);
  43. { 效果B: 等待500毫秒 -> 震动1秒 -> 等待2秒 -> 震动3秒 }
  44. //  LVibrator.vibrate(LJavaArray, -1);
  45. { 效果C: 效果B重复震动 }
  46. //  LVibrator.vibrate(LJavaArray, 0);
  47. { 取消震动(当手机暗屏或锁屏时会自动取消) }
  48. //  LVibrator.cancel;
  49. { 效果D: (等待500毫秒 -> 震动1秒 -> 等待2秒 -> 震动3秒)(先按原顺序震动一遍)
  50. 接着循环 [1000, 2000, 3000]
  51. ->(等待1秒 -> 震动2秒 - > 等待3秒)
  52. ->[等待1秒 -> 等待2秒 ... ]
  53. 这个听上去的效果像( 等待4秒 -> 震动2秒 )}
  54. // LVibrator.vibrate(LJavaArray, 1);
  55. { 效果E: (先按原顺序执行一遍), 接着不会震动(偶数为等待时间) }
  56. //  LVibrator.vibrate(LJavaArray, 3);
  57. { 效果F: 当然是报IndexOutBounds异常 }
  58. //  LVibrator.vibrate(LJavaArray, {!!!}4);
  59. end;

http://blog.csdn.net/flcop/article/details/13290779

Delphi XE5 Android 调用手机震动(通过JObject测试是否支持震动)的更多相关文章

  1. Delphi XE5 Android 调用手机震动

    uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array of Int6 ...

  2. Delphi XE5 Android 调用 Google ZXing

    { Google ZXing Call demo Delphi Version: Delphi XE5 Version 19.0.13476.4176 By: flcop(zylove619@hotm ...

  3. delphi xe5 android 调用照相机获取拍的照片

    本篇文章我们来看一下delphi xe5 在android程序里怎样启动照相机并获取所拍的照片,本代码取自xe自带打sample,路径为: C:\Users\Public\Documents\RAD ...

  4. 学习使用Delphi for android 调用Java类库

    http://blog.csdn.net/laorenshen/article/details/41148253 学习使用Delphi for android 调用Java类库 2014-11-15 ...

  5. Delphi XE5 android 获取网络状态

    unit Androidapi.JNI.Network; interface function IsConnected: Boolean; function IsWiFiConnected: Bool ...

  6. delphi xe5 android iny绿色版+最新SDK/NDK安装方法

    转自: http://bbs.2ccc.com/topic.asp?topicid=438595 首先感谢iny的绿色版,因为我的精简Win7 32位安装原版镜像4.63G过程正常,但是编译出错,后来 ...

  7. delphi xe5 android 服务端和手机端的源码下载

    xe5 android的服务端和手机客户端的源代码下载地址 http://files.cnblogs.com/nywh2008/AndroidTest.rar

  8. xe5 android 调用照相机获取拍的照片[转]

    本篇文章我们来看一下delphi xe5 在android程序里怎样启动照相机并获取所拍的照片,本代码取自xe自带打sample,路径为: C:\Users\Public\Documents\RAD ...

  9. Delphi XE5 android 获取网络状态《转》

    unit Androidapi.JNI.Network; interface function IsConnected: Boolean; function IsWiFiConnected: Bool ...

随机推荐

  1. PatentTips - Integrated circuit well bias circuitry

    1. Field of the Invention This invention relates in general to an integrated circuit and more specif ...

  2. 【codeforces 755C】PolandBall and Forest

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Linux网络编程——原始套接字能干什么?

    通常情况下程序员接所接触到的套接字(Socket)为两类: (1)流式套接字(SOCK_STREAM):一种面向连接的 Socket,针对于面向连接的TCP 服务应用: (2)数据报式套接字(SOCK ...

  4. Xcode崩溃定位:异常位置Exception的断点

    1.全局Exception断点 在XCode界面中按cmd + 6跳到Breakpoint的tab(或者点击下图左上第7个图标),然后点击左下角的+号,增加一个Exception的断点,如下图所示.这 ...

  5. 学习鸟哥的Linux私房菜笔记(3)——基础使用

    一.设备文件 设备在Linux中以特殊文件的形式存在 块(block)设备文件 字符(character)设备文件 设备文件所在位置 查看设备类型 二.虚拟控制台及用户身份切换 在系统中有12个虚拟控 ...

  6. 【BZOJ 1037】[ZJOI2008]生日聚会Party

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1037 [题意] [题解] /* 设f[i][j][k][l] 表示前i个人中,有j个男 ...

  7. Linux 增值服务中删除,自己主动和国家执行

    CAMS 在自己主动参加相关的服务安装过程.在最后的安装过程中会提示用户是否启动该服务,这样的服务才能生效,需要注意的是一个服务并不意味着系统启动过程中被添加到该服务后,会自己主动执行,只可用于ser ...

  8. selenium firefox 提取qq空间相册链接

    环境: selenium-java 3.9.1 firefox 57.0 geckodriver 0.19.1 1.大概的思路就是模拟用户点击行为,关于滚动条的问题,我是模拟下拉箭头,否则只能每个相册 ...

  9. word 论文排版 —— 按指定格式章节的自动编号

    在word中如何实现章节标题自动编号 标题样式与标题的编号是两个步骤,为标题建立编号是在为标题样式确定的基础后进行的.这是显而易见的,也即只有先定义了多级标题(也可使用 word 自带的标题样式),才 ...

  10. Ubuntu server使用命令行上板VPNclient

    Ubuntu server使用命令行上板VPNclient VPN,虚拟专用网络,这个技术还是非常有用的.近期笔者參与的项目中就使用上了VPN,大概情况是这种.有两个开发团队,在异地,代码服务器在深圳 ...