码迷,mamicode.com
首页 > 移动开发 > 详细

delphi 手机振动 IOS Android

时间:2015-10-14 17:42:17      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:

delphi  手机振动 IOS Android

https://community.embarcadero.com/blogs/entry/how-to-vibrate-ios-and-android-phones-using-firemonkey-and-xe8

http://blogs.embarcadero.com/davidi/2015/07/06/43894/

unit Umain;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls
{$IFDEF ANDROID}
  ,Androidapi.JNI.Os,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.Helpers,
  Androidapi.JNIBridge
{$ENDIF}
{$IFDEF IOS}
  ,IOSapi.MediaPlayer,
  IOSapi.CoreGraphics,
  FMX.Platform,
  FMX.Platform.IOS,
  IOSapi.UIKit,
  Macapi.ObjCRuntime,
  Macapi.ObjectiveC,
  iOSapi.Cocoatypes,
  Macapi.CoreFoundation,
  iOSapi.Foundation,
  iOSapi.CoreImage,
  iOSapi.QuartzCore,
  iOSapi.CoreData
{$ENDIF}
  ;

{$IFDEF IOS}
Const
  libAudioToolbox        = ‘/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox‘;
  kSystemSoundID_vibrate = $FFF;

Procedure AudioServicesPlaySystemSound( inSystemSoundID: integer ); Cdecl; External libAudioToolbox Name _PU + ‘AudioServicesPlaySystemSound‘;
{$ENDIF}


type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
{$IFDEF ANDROID}
Var
  Vibrator:JVibrator;
{$ENDIF}
begin
{$IFDEF ANDROID}
  Vibrator:=TJVibrator.Wrap((SharedActivityContext.getSystemService(TJContext.JavaClass.VIBRATOR_SERVICE) as ILocalObject).GetObjectID);
  // Vibrate for 500 milliseconds
  Vibrator.vibrate(500);
{$ENDIF}
{$IFDEF IOS}
  AudioServicesPlaySystemSound( kSystemSoundID_vibrate );
{$ENDIF}
end;

end.

  

delphi 手机振动 IOS Android

标签:

原文地址:http://www.cnblogs.com/cb168/p/4877865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!