相关资料:http://blog.csdn.net/laorenshen/article/details/41148843
结果:
1.打开Vibrate权限为True。
2.规律震动我没感觉出来,有了解情况的请联系我。多谢了。
实例代码:
1 unit Unit1; 2 3 interface 4 5 uses 6 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, 8 Androidapi.Helpers,// 9 FMX.Helpers.Android,// 10 Androidapi.JNI.App,// 11 Androidapi.JNI.Os,// 12 Androidapi.JNIBridge,// 13 FMX.StdCtrls, FMX.Controls.Presentation;// 14 type 15 TForm1 = class(TForm) 16 Button1: TButton; 17 Button2: TButton; 18 Button3: TButton; 19 Button4: TButton; 20 Label1: TLabel; 21 procedure Button1Click(Sender: TObject); 22 procedure Button2Click(Sender: TObject); 23 procedure Button3Click(Sender: TObject); 24 procedure Button4Click(Sender: TObject); 25 private 26 { Private declarations } 27 public 28 { Public declarations } 29 end; 30 31 var 32 Form1: TForm1; 33 34 implementation 35 36 {$R *.fmx} 37 {$R *.NmXhdpiPh.fmx ANDROID} 38 39 function GetVibratorArray(const AintArr:array of Int64):TJavaArray<Int64>;//震动规律函数 40 var 41 Lindex: Integer; 42 begin 43 Result:=TJavaArray<Int64>.Create(Length(AintArr)); 44 for Lindex:=Low(AintArr) to High(AintArr) do 45 Result.Items[Lindex] := AintArr[Lindex]; 46 end; 47 48 procedure TForm1.Button1Click(Sender: TObject); 49 var 50 LVibrator: JVibrator; 51 begin 52 LVibrator := TJVibrator.Wrap((SharedActivity.getSystemService(TJActivity.javaClass.VIBRATOR_SERVICE) as iLocalObject).GetObjectID);//引用震动 53 if not LVibrator.hasVibrator then 54 begin 55 Showmessage('手机不支持震动'); 56 Exit; 57 end; 58 LVibrator.vibrate(200);//震动200ms 59 end; 60 61 procedure TForm1.Button2Click(Sender: TObject); 62 var 63 LVibrator:JVibrator; 64 LJavaArray:TJavaArray<Int64>; 65 begin 66 LVibrator := TJVibrator.Wrap((SharedActivity.getSystemService(TJActivity.javaClass.VIBRATOR_SERVICE) as iLocalObject).GetObjectID);//调用震动 67 LVibrator.cancel;//停止震动 68 end; 69 70 procedure TForm1.Button3Click(Sender: TObject); 71 var 72 LVibrator:JVibrator; 73 LJavaArray:TJavaArray<Int64>; 74 begin 75 LVibrator := TJVibrator.Wrap((SharedActivity.getSystemService(TJActivity.javaClass.VIBRATOR_SERVICE) as iLocalObject).GetObjectID); 76 if not LVibrator.hasVibrator then 77 begin 78 Showmessage('手机不支持震动'); 79 Exit; 80 end; 81 LJavaArray := GetVibratorArray([200, 1000, 3000, 5000]);//调用震动规律//我没感觉出来,如果你们能感觉出来,给我说一下。 82 LVibrator.vibrate(LJavaArray, -1);//震动一遍 83 end; 84 85 procedure TForm1.Button4Click(Sender: TObject); 86 var 87 LVibrator:JVibrator; 88 LJavaArray:TJavaArray<Int64>; 89 begin 90 LVibrator:=TJVibrator.Wrap((SharedActivity.getSystemService(TJActivity.javaClass.VIBRATOR_SERVICE) as iLocalObject).GetObjectID); 91 if not LVibrator.hasVibrator then 92 begin 93 Showmessage('手机不支持震动'); 94 Exit; 95 end; 96 LJavaArray := GetVibratorArray([200, 1000, 3000, 5000]);//调用震动规律 97 LVibrator.vibrate(LJavaArray, 0);//重复 //-1:震动一遍 0:重复 >0:指定震动遍数 98 end; 99 100 end.