识字粗堪供赋役,不须辛苦慕公卿。这篇文章主要讲述Delphi xe7 up1 调用android振动功能相关的知识,希望能为你提供帮助。
Delphi
xe7
up1
调用android振动功能
振动用到以下4个单元:
Androidapi.JNI.App,Androidapi.JNIBridge,Androidapi.JNI.Os,Androidapi.Helpers
使用方法:
var
LVibrator:
JVibrator;
begin
LVibrator
:=
TJVibrator.Wrap
((SharedActivity.getSystemService(TJActivity.javaClass.VIBRATOR_SERVICE)
as
ILocalObject).GetObjectID);
//
调用振动
if
not
LVibrator.hasVibrator
then
begin
ShowMessage(\'手机不支持震动\');
Exit;
end;
LVibrator.vibrate(500);
//
振动500毫秒
最后在Project
Options中设置Uses
Permissions将Vibrate设为true
详细程序如下:
unit
Unit6;
interface
uses
System.SysUtils,
System.Types,
System.UITypes,
System.Classes,
System.Variants,Androidapi.JNI.App,
FMX.Types,
FMX.Controls,
FMX.Forms,
FMX.Graphics,
FMX.Dialogs,
FMX.StdCtrls,
Androidapi.JNIBridge,Androidapi.JNI.Os,Androidapi.Helpers;
type
TForm6
=
class(TForm)
Button1:
TButton;
procedure
Button1Click(Sender:
TObject);
private
{
Private
declarations
}
public
{
Public
declarations
}
end;
var
Form6:
TForm6;
implementation
{$R
*.fmx}
procedure
TForm6.Button1Click(Sender:
TObject);
var
LVibrator:
JVibrator;
begin
LVibrator
:=
TJVibrator.Wrap
((SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_SERVICE)
as
ILocalObject).GetObjectID);
//
调用振动
if
not
LVibrator.hasVibrator
then
begin
ShowMessage(\'手机不支持震动\');
Exit;
end;
LVibrator.vibrate(500);
//
振动500毫秒
end;
end.
文章图片
【Delphi xe7 up1 调用android振动功能】https://www.cnblogs.com/qiufeng2014/p/4280847.html
推荐阅读
- AutoMapper在C#中的有趣应用
- 微信中无法下载APP的解决方案(微信自动跳转浏览器打开下载链接)
- Android-Java-单例模式优化&多线程并发
- delphi android 录像(使用了JMediaRecorder,MediaRecorder的使用方法)
- Android-Java-synchronized静态方法&字节码文件对象
- Java代码启动Appium server
- 理解Android虚拟机体系结构
- Android数据库内容变化的监听
- Android 简单的语音播报