zoukankan      html  css  js  c++  java
  • Delphi xe7 up1 调用android振动功能

    Delphi xe7 up1 调用android振动功能

    振动用到以下4个单元:

    Androidapi.JNI.App,Androidapi.JNIBridge,Androidapi.JNI.Os,Androidapi.Helpers

    使用方法:

    var

      LVibrator: JVibrator;

    begin

        LVibrator := TJVibrator.Wrap

          ((SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_SERVICE)

          as ILocalObject).GetObjectID); // 调用振动

        if not LVibrator.hasVibrator then

        begin

          ShowMessage('手机不支持震动');

          Exit;

        end;

        LVibrator.vibrate(500); // 振动500毫秒

    最后在Project Options中设置Uses PermissionsVibrate设为true

    详细程序如下:

    unit Unit6;

    interface

    uses

      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,Androidapi.JNI.App,

      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,

      Androidapi.JNIBridge,Androidapi.JNI.Os,Androidapi.Helpers;

    type

      TForm6 = class(TForm)

        Button1: TButton;

        procedure Button1Click(Sender: TObject);

      private

        { Private declarations }

      public

        { Public declarations }

      end;

    var

      Form6: TForm6;

    implementation

    {$R *.fmx}

    procedure TForm6.Button1Click(Sender: TObject);

    var

      LVibrator: JVibrator;

    begin

        LVibrator := TJVibrator.Wrap

          ((SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_SERVICE)

          as ILocalObject).GetObjectID); // 调用振动

        if not LVibrator.hasVibrator then

        begin

          ShowMessage('手机不支持震动');

          Exit;

        end;

        LVibrator.vibrate(500); // 振动500毫秒

    end;

    end.

  • 相关阅读:
    NSIS打包electron程序为exe安装包
    3、electron打包生成exe文件
    7、Shiro加密和加盐
    6、Shiro之自定义realm
    5、Shiro之jdbcRealm认证授权
    Jmeter-提取Json数据进行关联
    CentOS7 adb
    centos 7 安装pip和pip3
    最新Centos7安装python3并与python2共存
    centos7安装chrome浏览器
  • 原文地址:https://www.cnblogs.com/lantianhf/p/4335709.html
Copyright © 2011-2022 走看看