bangnaga

How to Vibrate Android or Iphone

Dec 24th, 2019
787
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Uses
  2.  
  3. {$IFDEF ANDROID}
  4.   ,Androidapi.JNI.Os,
  5.   Androidapi.JNI.GraphicsContentViewText,
  6.   Androidapi.Helpers,
  7.   Androidapi.JNIBridge
  8. {$ENDIF}
  9. {$IFDEF IOS}
  10.   ,IOSapi.MediaPlayer,
  11.   IOSapi.CoreGraphics,
  12.   FMX.Platform,
  13.   FMX.Platform.IOS,
  14.   IOSapi.UIKit,
  15.   Macapi.ObjCRuntime,
  16.   Macapi.ObjectiveC,
  17.   iOSapi.Cocoatypes,
  18.   Macapi.CoreFoundation,
  19.   iOSapi.Foundation,
  20.   iOSapi.CoreImage,
  21.   iOSapi.QuartzCore,
  22.   iOSapi.CoreData
  23. {$ENDIF}
  24.   ;
  25.  
  26. {$IFDEF IOS}
  27. Const
  28.   libAudioToolbox        = '/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox';
  29.   kSystemSoundID_vibrate = $FFF;
  30.  
  31. Procedure AudioServicesPlaySystemSound( inSystemSoundID: integer ); Cdecl; External libAudioToolbox Name _PU + 'AudioServicesPlaySystemSound';
  32. {$ENDIF}
  33.  
  34.  
  35.  
  36. //In your Application
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. {$IFDEF ANDROID}
  40. Var
  41.   Vibrator:JVibrator;
  42. {$ENDIF}
  43. begin
  44. {$IFDEF ANDROID}
  45.   Vibrator:=TJVibrator.Wrap((SharedActivityContext.getSystemService(TJContext.JavaClass.VIBRATOR_SERVICE) as ILocalObject).GetObjectID);
  46.   // Vibrate for 500 milliseconds
  47.   Vibrator.vibrate(500);
  48. {$ENDIF}
  49. {$IFDEF IOS}
  50.   AudioServicesPlaySystemSound( kSystemSoundID_vibrate );
  51. {$ENDIF}
  52. end;
RAW Paste Data