Delphi XE5 Android Phone vibrate (through Jobject test support vibration)

Source: Internet
Author: User

The source code is as follows:

[Delphi]View PlainCopy
  1. Uses
  2. Androidapi. JNI. Os,
  3. Androidapi.  Jnibridge;
  4. function Getvibratorarray (const Aintarr: array of Int64): tjavaarray<int64>;
  5. Var
  6. Lindex:integer;
  7. Begin
  8. Result: = Tjavaarray<int64>. Create (Length (Aintarr));
  9. For LIndex: = Low (Aintarr) to High (Aintarr) does
  10. Result.  Items[lindex]: = Aintarr[lindex];
  11. End
  12. Procedure Vibratortest;
  13. Var
  14. Lvibratorobj:jobject;
  15. Lvibrator:jvibrator;
  16. ljavaarray:tjavaarray<int64>;
  17. Begin
  18. {Vibrator Summary:
  19. Cancel (): Off vibration
  20. Hasvibrator (): Check if hardware is supported
  21. Vibrate (long milliseconds): vibration milliseconds ms
  22. Vibrate (long[] pattern, int repeat): Vibrate by given array}
  23. {You need to turn on vibrator permissions}
  24. //<del>lvibrator: = tjvibrator.create as jvibrator;</del>
  25. {Create 2014-5-8 update using the official recommended method}
  26. Lvibratorobj: = Sharedactivity. Getsystemservice (
  27. Tjcontext. Javaclass.    Vibrator_service);
  28. Lvibrator: = Tjvibrator. Wrap ((lvibratorobj as ilocalobject).  Getobjectid);
  29. {Test whether the phone supports vibration}
  30. if not lvibrator. Hasvibrator Then
  31. begin
  32. ShowMessage (' mobile phone does not support vibration ');
  33. Exit;
  34. end;
  35. {Test procedure vibrate (milliseconds:int64); cdecl; overload;}
  36. {Effect A: immediate vibration 800 milliseconds}
  37. Lvibrator.vibrate (800);
  38. {Test procedure vibrate (pattern:tjavaarray<int64>; repeat_: Integer); cdecl; overload;
  39. Pattern: For vibrating array parameters, even for waiting time (ms), odd for vibration duration (ms)
  40. Repeat_:-1: Shake only once; >-1: Start repeating vibrations from the position of index Repeat_}
  41. {Create Test array}
  42. Ljavaarray: = Getvibratorarray ([3000, +, + ]);
  43. {effect B: Wait 500 milliseconds, vibration 1 seconds, wait 2 seconds, shake 3 seconds}
  44. Lvibrator.vibrate (Ljavaarray,-1);
  45. {effect c: effect B repeats vibration}
  46. Lvibrator.vibrate (Ljavaarray, 0);
  47. {Cancel vibrate (automatically cancels when the phone is in a dark screen or lock screen)}
  48. Lvibrator.cancel;
  49. {effect D: (wait 500 milliseconds, vibration 1 seconds, wait for 2 seconds, shake 3 seconds) (shake first in the original order)
  50. then loop [1000, 2000, 3000]
  51. (Wait 1 seconds, shake 2 seconds-> Wait 3 seconds)
  52. ->[wait 1 seconds--wait 2 seconds ...]
  53. This sounds like (wait 4 seconds, shake 2 seconds)}
  54. //Lvibrator.vibrate (Ljavaarray, 1);
  55. {effect E: (Executed once in the original order), then no vibration (even waiting time)}
  56. Lvibrator.vibrate (Ljavaarray, 3);
  57. {effect F: Of course, Report indexoutbounds exception}
  58. Lvibrator.vibrate (Ljavaarray, {!!!} 4);
  59. End


http://blog.csdn.net/flcop/article/details/13290779

Delphi XE5 Android Phone vibrate (through Jobject test support vibration)

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.