振动用到以下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.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.
https://www.cnblogs.com/qiufeng2014/p/4280847.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。