uses
Androidapi.JNI.Os,
Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array of Int64): TJavaArray<Int64>;
var
LIndex: Integer;
begin
Result := TJavaArray<Int64>.Create(Length(AIntArr));
for LIndex := Low(AIntArr) to High(AIntArr) do
Result.Items[LIndex] := AIntArr[LIndex];
end; procedure VibratorTest;
var
LVibrator: JVibrator;
LJavaArray: TJavaArray<Int64>;
begin
{ Vibrator概要:
cancel(): 关闭震动
hasVibrator():检查硬件是否支持
vibrate(long milliseconds): 震动milliseconds毫秒
vibrate(long[] pattern, int repeat):按给定数组震动 } { 需要开启Vibrator权限 }
LVibrator := TJVibrator.Create as JVibrator; { 测试手机是否支持震动 }
if not LVibrator.hasVibrator then
begin
ShowMessage('手机不支持震动');
Exit;
end; { Test procedure vibrate(milliseconds: Int64); cdecl; overload; } { 效果A: 立即震动 800 毫秒 }
// LVibrator.vibrate(); { Test procedure vibrate(pattern: TJavaArray<Int64>; repeat_: Integer); cdecl; overload;
pattern: 为震动数组参数,偶数代表等待时间(ms), 奇数代表震动持续时间(ms)
repeat_: -1: 只震动一遍; > -1: 从Index为 repeat_ 的位置开始重复震动 } { 创建测试数组 }
LJavaArray := GetVibratorArray([, , , ]); { 效果B: 等待500毫秒 -> 震动1秒 -> 等待2秒 -> 震动3秒 }
// LVibrator.vibrate(LJavaArray, -); { 效果C: 效果B重复震动 }
// LVibrator.vibrate(LJavaArray, ); { 取消震动(当手机暗屏或锁屏时会自动取消) }
// LVibrator.cancel; { 效果D: (等待500毫秒 -> 震动1秒 -> 等待2秒 -> 震动3秒)(先按原顺序震动一遍)
接着循环 [1000, 2000, 3000]
->(等待1秒 -> 震动2秒 - > 等待3秒)
->[等待1秒 -> 等待2秒 ... ]
这个听上去的效果像( 等待4秒 -> 震动2秒 )}
// LVibrator.vibrate(LJavaArray, ); { 效果E: (先按原顺序执行一遍), 接着不会震动(偶数为等待时间) }
// LVibrator.vibrate(LJavaArray, ); { 效果F: 当然是报IndexOutBounds异常 }
// LVibrator.vibrate(LJavaArray, {!!!}); end;

Delphi XE5 Android 调用手机震动的更多相关文章

  1. Delphi XE5 Android 调用手机震动(通过JObject测试是否支持震动)

    源码如下: uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array o ...

  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. html5调用手机震动

    在h5里面里面,浏览器对象有个vibrate属性.顾名思义,翻译过来就是震动的意思,这个api属性方法如下: 要调用的例子 if (window.navigator.vibrate) window.n ...

  6. Unity3d之音效播放和调用手机震动

    http://blog.csdn.net/sunshine_1984/article/details/12943979 今天研究了下Unity3d音效播放相关内容,整理下实现细节. 1,添加音效文件到 ...

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

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

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

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

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

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

随机推荐

  1. Spring cloud系列之win10 下安装 ZooKeeper 的方法

    ZooKeeper 下载地址: https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 1.将下载的文件解压到指定的目录中 2.进入conf文件夹 ...

  2. test pthread code

    #include <iostream> #include <pthread.h> using namespace std; ; void * add(void *); pthr ...

  3. .net core WebApi Interlocked配合ManualResetEventSlim实现并发同步

    由于项目有某种需求,在WebApi中,有大量的请求需要操作相同的数据,因此需要用到并发同步机制去操作共享的数据. 本次配合使用Interlocked和ManualResetEventSlim来实现并发 ...

  4. Crontab中的除号(slash)到底怎么用?(转载)

    转载于:https://www.cnblogs.com/cocowool/p/5865397.html crontab 是Linux中配置定时任务的工具,在各种配置中,我们经常会看到除号(Slash) ...

  5. SEH X86

    ( windows 提供的异常处理机制实际上只是一个简单的框架,一般情况下开发人员都不会直接用到.我们通常所用的异常处理(比如 C++ 的 throw.try.catch)都是编译器在系统提供的异常处 ...

  6. Jmeter分布式及在Linux上执行jmeter脚本

    Jmeter分布式 主控机即自己的电脑,控制并发数 压力机即别人的机器,和主控机一起添加压力 1.其他的压力机需要启动Jmeter-server.bat 启动成功页面 2.主控机的Jmeter 的bi ...

  7. # 学号 20175223 《Java程序设计》第3周学习总结

    学号 20175223 <Java程序设计>第3周学习总结 教材学习内容总结 第四章要点: 要点1:面向对象三个性质:封装性.继承.多态: 要点2:类:类声明.类体.成员变量.方法.类的U ...

  8. 用IDEA时,类/方法提示"class/method **** is never used"

    https://segmentfault.com/q/1010000005996275?_ea=978306 清理下缓存试下.在 File -> Invalidate Caches 下,会重启 ...

  9. RSA加密解密实现(JAVA)

    1.关于RSA算法的原理解析参考:http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html 2.RSA密钥长度.明文长度和密 ...

  10. L2-010. 排座位(并查集)*

    L2-010. 排座位 参考博客 #include<iostream> #include<math.h> using namespace std; ]; ][]; int fi ...