Delphi XE5 Android 调用手机震动(通过JObject测试是否支持震动)
源码如下:
- 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
- LVibratorObj: JObject;
- LVibrator: JVibrator;
- LJavaArray: TJavaArray<Int64>;
- begin
- { Vibrator概要:
- cancel(): 关闭震动
- hasVibrator():检查硬件是否支持
- vibrate(long milliseconds): 震动milliseconds毫秒
- vibrate(long[] pattern, int repeat):按给定数组震动 }
- { 需要开启Vibrator权限 }
- // <del>LVibrator := TJVibrator.Create as JVibrator;</del>
- { 使用官方推荐方式创建 2014-5-8 update}
- LVibratorObj := SharedActivity.getSystemService(
- TJContext.JavaClass.VIBRATOR_SERVICE);
- LVibrator := TJVibrator.Wrap((LVibratorObj as ILocalObject).GetObjectID);
- { 测试手机是否支持震动 }
- if not LVibrator.hasVibrator then
- begin
- ShowMessage('手机不支持震动');
- Exit;
- end;
- { Test procedure vibrate(milliseconds: Int64); cdecl; overload; }
- { 效果A: 立即震动 800 毫秒 }
- // LVibrator.vibrate(800);
- { Test procedure vibrate(pattern: TJavaArray<Int64>; repeat_: Integer); cdecl; overload;
- pattern: 为震动数组参数,偶数代表等待时间(ms), 奇数代表震动持续时间(ms)
- repeat_: -1: 只震动一遍; > -1: 从Index为 repeat_ 的位置开始重复震动 }
- { 创建测试数组 }
- LJavaArray := GetVibratorArray([500, 1000, 2000, 3000]);
- { 效果B: 等待500毫秒 -> 震动1秒 -> 等待2秒 -> 震动3秒 }
- // LVibrator.vibrate(LJavaArray, -1);
- { 效果C: 效果B重复震动 }
- // LVibrator.vibrate(LJavaArray, 0);
- { 取消震动(当手机暗屏或锁屏时会自动取消) }
- // LVibrator.cancel;
- { 效果D: (等待500毫秒 -> 震动1秒 -> 等待2秒 -> 震动3秒)(先按原顺序震动一遍)
- 接着循环 [1000, 2000, 3000]
- ->(等待1秒 -> 震动2秒 - > 等待3秒)
- ->[等待1秒 -> 等待2秒 ... ]
- 这个听上去的效果像( 等待4秒 -> 震动2秒 )}
- // LVibrator.vibrate(LJavaArray, 1);
- { 效果E: (先按原顺序执行一遍), 接着不会震动(偶数为等待时间) }
- // LVibrator.vibrate(LJavaArray, 3);
- { 效果F: 当然是报IndexOutBounds异常 }
- // LVibrator.vibrate(LJavaArray, {!!!}4);
- end;
http://blog.csdn.net/flcop/article/details/13290779
Delphi XE5 Android 调用手机震动(通过JObject测试是否支持震动)的更多相关文章
- Delphi XE5 Android 调用手机震动
uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array of Int6 ...
- Delphi XE5 Android 调用 Google ZXing
{ Google ZXing Call demo Delphi Version: Delphi XE5 Version 19.0.13476.4176 By: flcop(zylove619@hotm ...
- delphi xe5 android 调用照相机获取拍的照片
本篇文章我们来看一下delphi xe5 在android程序里怎样启动照相机并获取所拍的照片,本代码取自xe自带打sample,路径为: C:\Users\Public\Documents\RAD ...
- 学习使用Delphi for android 调用Java类库
http://blog.csdn.net/laorenshen/article/details/41148253 学习使用Delphi for android 调用Java类库 2014-11-15 ...
- Delphi XE5 android 获取网络状态
unit Androidapi.JNI.Network; interface function IsConnected: Boolean; function IsWiFiConnected: Bool ...
- delphi xe5 android iny绿色版+最新SDK/NDK安装方法
转自: http://bbs.2ccc.com/topic.asp?topicid=438595 首先感谢iny的绿色版,因为我的精简Win7 32位安装原版镜像4.63G过程正常,但是编译出错,后来 ...
- delphi xe5 android 服务端和手机端的源码下载
xe5 android的服务端和手机客户端的源代码下载地址 http://files.cnblogs.com/nywh2008/AndroidTest.rar
- xe5 android 调用照相机获取拍的照片[转]
本篇文章我们来看一下delphi xe5 在android程序里怎样启动照相机并获取所拍的照片,本代码取自xe自带打sample,路径为: C:\Users\Public\Documents\RAD ...
- Delphi XE5 android 获取网络状态《转》
unit Androidapi.JNI.Network; interface function IsConnected: Boolean; function IsWiFiConnected: Bool ...
随机推荐
- Navigation Pane不能设置显示标题
https://msdn.microsoft.com/VBA/Word-VBA/articles/view-showheading-method-word https://social.msdn.mi ...
- Java中a=a+b 与 a+=b差别
一般觉得a=a+b的运行效率是低于a+=b的,由于它多进行了一步中间变量的操作,并且会多占用一个变量的空间.而Java编译器默认对其进行了优化,优化之后两条语句都当做 a+=b来运行了,所以实际上是没 ...
- Android图文具体解释属性动画
Android中的动画分为视图动画(View Animation).属性动画(Property Animation)以及Drawable动画.从Android 3.0(API Level 11)開始. ...
- [NPM] Use a shorthand syntax for running multiple npm scripts with npm-run-all
Running multiple scripts in series or in parallel can become very verbose. Using a tool such as npm- ...
- QWidget标题栏双击事件(QWidget::event里拦截NonClientAreaMouseButtonDblClick)
widget.h 1 virtual bool event(QEvent *event); widget.cpp bool Widget::event(QEvent *event) { if (eve ...
- github push出错(1)You can't push to git:// Use https://
fatal: remote error: You can't push to git://github.com/niexiaobo/remote.git Use https://github.com/ ...
- matplotlib plot 绘图函数发生阻塞(block)时的解决方法
Is there a way to detach matplotlib plots so that the computation can continue? 在一般编辑器中: from matplo ...
- 【b603】作业调度方案
Time Limit: 1 second Memory Limit: 50 MB [问题描述] 我们现在要利用m台机器加工n个工件,每个工件都有m道工序,每道工序都在不同的指定的机器上完成.每个工件的 ...
- Vue中import '@...'是什么
今天看新项目代码,有import '@/assets/css/theme/index.css'一类的代码,里面的@是做什么的呢. 找到这篇文章https://www.cnblogs.com/bos ...
- iOS开发 - Swift - 自己写的一个九宫格解锁的Demo
前段时间做项目,公司要用到一个九宫格的手势解锁的需求. 虽然在很多地方都可以找到写好的第三方源码, 但是我的性格是不喜欢Ctrl+V的,于是自己凭着理解敲了一个出来,功能很简单,只是单纯的返回结果.附 ...