Vibrate, is called the Android API JNI inside the function, these are called Java, such as the following reference,
Uses
FMX. Helpers.android,
ANDROIDAPI.JNI.APP,
Androidapi.JNI.Os,
Androidapi.jnibridge, Fmx.stdctrls;
It's still a few steps,
1 Create a new mobile project
Open Xe6, file----new----Firemonkeymobile Application-delphi
2 Select Black Application click OK.
3 in the window that opens, put a few button controls.
4. Click the Save button to save the program in your pre-set directory.
5. Write the Click event Write code for button buttons:
Procedure Tform1.button2click (Sender:tobject);
Var
Lvibrator:jvibrator;
Begin
Lvibrator:=tjvibrator.wrap ((Sharedactivity.getsystemservice (TJActivity.javaClass.VIBRATOR_SERVICE) as Ilocalobject). Getobjectid);//reference Vibration
If not Lvibrator.hasvibrator then
Begin
ShowMessage (' Mobile phone does not support vibration ');
Exit
End
Lvibrator.vibrate (200);//Vibration 200ms
End
6 run to see, the phone directly on the out, hehe
7 Add a few more buttons, see, Stop the vibrate button
Procedure Tform1.button5click (Sender:tobject);
Var
Lvibrator:jvibrator;
ljavaarray:tjavaarray<int64>;
Begin
Lvibrator:=tjvibrator.wrap ((Sharedactivity.getsystemservice (TJActivity.javaClass.VIBRATOR_SERVICE) as Ilocalobject). Getobjectid);//Call Vibrate
Lvibrator.cancel;//Stop shaking immediately
End
8 and then, if you want to, how do you get a regular shake? Continue adding 2 buttons and a function
function Getvibratorarray (const aintarr:array of Int64): tjavaarray<int64>;//Vibration Law functions
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 Tform1.button3click (sender:tobject);
var
lvibrator:jvibrator;
LJavaArray:TJavaArray<int64>;
Begin
lvibrator:=tjvibrator.wrap ((Sharedactivity.getsystemservice ( TJActivity.javaClass.VIBRATOR_SERVICE) as Ilocalobject). Getobjectid);
if not lvibrator.hasvibrator then
begin
showmessage (' Mobile phone does not support vibration ');
exit;
end;
ljavaarray:=getvibratorarray ([200,1000,3000,5000]);//Call Vibration rule
lvibrator.vibrate ( LJAVAARRAY,-1);//Do not repeat, vibrate once
End
Procedure Tform1.button4click (Sender:tobject);
Var
Lvibrator:jvibrator;
ljavaarray:tjavaarray<int64>;
Begin
Lvibrator:=tjvibrator.wrap ((Sharedactivity.getsystemservice (TJActivity.javaClass.VIBRATOR_SERVICE) as Ilocalobject). Getobjectid);
If not Lvibrator.hasvibrator then
Begin
ShowMessage (' Mobile phone does not support vibration ');
Exit
End
Ljavaarray:=getvibratorarray ([200,1000,3000,5000]);//Call Vibration Law
Lvibrator.vibrate (ljavaarray,0)//v Repeat, more than 0 parameters, you can specify the number of vibrations
End
Note: When running, the phone does not black screen.
http://blog.csdn.net/laorenshen/article/details/41148843
Delphi XE6 for Android make phone vibrate (call Java function)