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. Median absolute deviation | Singular Value Decomposition奇异值分解 | cumulative sums |

    Consider the data (1, 1, 2, 2, 4, 6, 9). It has a median value of 2. The absolute deviations about 2 ...

  2. 继承ActionSupper类报错 --Struts2

    如下图所示,继承ActionSupper类报错: 原因:缺少Struts2中JAR包,具体是:

  3. httpd常见配置

    httpd常见配置 配置文件 /etc/httpd/conf/httpd.conf    主配置文件 /etc/httpd/conf.d/*.conf  辅助配置文件 配置文件语法检查及重新加载配置文 ...

  4. element-ui <el-input> 注册blur事件

    <template> <div class="demo"> <el-input placeholder="注册blur事件" v- ...

  5. ceph crush的问题

    ceph crush的问题看一遍忘一遍,现将<ceph源码分析>一书中相关章节摘抄如下: 4.2.1 层级化的Cluster Map例4-1 Cluster Map定义层级化的Cluste ...

  6. linux 搭建rap记录

    1 安装 jdk1.8版本及以上 2 安装 apache-tomcat 3 安装 redis 最后编辑session配置和数据库配置 <session-config><session ...

  7. CentOS 使用yum命令安装出现错误提示”could not retrieve mirrorlist http://mirrorlist.centos.org

    CentOS 使用yum命令安装出现错误提示"could not retrieve mirrorlist http://mirrorlist.centos.org这个错误, 在网上找了好多, ...

  8. Python3版本中的filter函数,map函数和reduce函数

    一.filter函数: filter()为已知的序列的每个元素调用给定的布尔函数,调用中,返回值为非零的元素将被添加至一个列表中 def f1(x): if x>20: return True ...

  9. 2、AngularJs 过滤器($filter)

    1.内置过滤器: currency ({{123|currency}}) date (medium\short\fullDate\longDate\mediumDate\shortDate\mediu ...

  10. 网络性能测试工具-Iperf

    一.简单介绍 Iperf是一个网络性能测试工具,Iperf可以测试TCP和UDP带宽质量,Iperf可以测量最大TCP带宽,具有多种参数和UDP特性.Iperf可以报告带宽,延迟抖动和数据包丢失.利用 ...