Delphi XE 5 Android呼び出し携帯バイブレーション
5632 ワード
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(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;