Delphi XE6 for Android make phone vibrate (call Java function)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.