1. {
  2. Google ZXing Call demo
  3.  
  4. Delphi Version: Delphi XE5 Version 19.0.13476.4176
  5.  
  6. By: flcop(zylove619@hotmail.com)
  7. }
  8.  
  9. unit UMain;
  10.  
  11. interface
  12.  
  13. uses
  14. System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  15. FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  16. FMX.Layouts, FMX.Memo,
  17.  
  18. System.Rtti,
  19. FMX.Helpers.Android,
  20. Androidapi.JNI.Net,
  21. Androidapi.JNI.GraphicsContentViewText,
  22. Androidapi.JNI.JavaTypes,
  23. FMX.platform,
  24. FMX.Platform.Android;
  25.  
  26. type
  27. TFrmMain = class(TForm)
  28. Memo1: TMemo;
  29. Button1: TButton;
  30. Button2: TButton;
  31. Button3: TButton;
  32. PanelOpt: TPanel;
  33. Panel2: TPanel;
  34. SBTitle: TSpeedButton;
  35. procedure Button1Click(Sender: TObject);
  36. procedure FormCreate(Sender: TObject);
  37. procedure SBTitleClick(Sender: TObject);
  38. private
  39. { Private declarations }
  40. FClipboardService: IFMXClipboardService;
  41. FClipboardValue: TValue;
  42. FZXingCalled: Boolean;
  43. procedure CallZXing(const ACodeMode: string);
  44. function IsIntentCallable(const AIntent: JIntent): Boolean;
  45. function GetZXingIntent: JIntent;
  46. procedure ClipboardSave;
  47. procedure ClipboardBack;
  48. procedure ShowInfo(const AInfo: string);
  49. function HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
  50. procedure CheckEnvironment;
  51. procedure OpenURL(const AURL: string);
  52. public
  53. { Public declarations }
  54. end;
  55.  
  56. var
  57. FrmMain: TFrmMain;
  58.  
  59. implementation
  60.  
  61. {$R *.fmx}
  62.  
  63. const
  64. CodeModes: array[..] of string = ('PRODUCT_MODE', 'QR_CODE_MODE', 'SCAN_MODE');
  65.  
  66. procedure TFrmMain.Button1Click(Sender: TObject);
  67. begin
  68. // , ,
  69. CallZXing(CodeModes[TButton(Sender).Tag]);
  70. end;
  71.  
  72. procedure TFrmMain.CallZXing(const ACodeMode: string);
  73. var
  74. LIntent: JIntent;
  75. begin
  76. ClipboardSave;
  77. FClipboardService.SetClipboard('');
  78. LIntent := GetZXingIntent();
  79. LIntent.putExtra(StringToJString('SCAN_MODE'), StringToJString(ACodeMode));
  80. SharedActivity.startActivityForResult(LIntent, );
  81. FZXingCalled := True;
  82. end;
  83.  
  84. procedure TFrmMain.CheckEnvironment;
  85. var
  86. LFMXApplicationEventService: IFMXApplicationEventService;
  87. LIsZXingCallable: Boolean;
  88. LStr: string;
  89. begin
  90. if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService,
  91. IInterface(LFMXApplicationEventService)) then
  92. LFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
  93. else
  94. LStr := '调用失败,不支持IFMXApplicationEventService!';
  95.  
  96. if not TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService,
  97. IInterface(FClipboardService)) then
  98. LStr := LStr + sLineBreak + '调用失败, 不支持IFMXClipboardService!';
  99.  
  100. LIsZXingCallable := IsIntentCallable(GetZXingIntent);
  101. if not LIsZXingCallable then
  102. begin
  103. SBTitle.Text := '点我去ZXing下载页...';
  104. SBTitle.OnClick := SBTitleClick;
  105. LStr := LStr + sLineBreak + '未发现ZXing, 请安装ZXing后重新启动本程序';
  106. end else
  107. SBTitle.Text := 'Google ZXing Call';
  108.  
  109. ShowInfo(LStr.Trim);
  110.  
  111. PanelOpt.Enabled := Assigned(LFMXApplicationEventService) and
  112. Assigned(FClipboardService) and LIsZXingCallable;
  113. end;
  114.  
  115. procedure TFrmMain.ClipboardBack;
  116. begin
  117. FClipboardService.SetClipboard(FClipboardValue);
  118. end;
  119.  
  120. procedure TFrmMain.ClipboardSave;
  121. begin
  122. FClipboardValue := FClipboardService.GetClipboard;
  123. end;
  124.  
  125. procedure TFrmMain.FormCreate(Sender: TObject);
  126. begin
  127. CheckEnvironment;
  128. end;
  129.  
  130. function TFrmMain.GetZXingIntent: JIntent;
  131. const
  132. GOOGLE_ZXING = 'com.google.zxing.client.android.SCAN';
  133. GOOGLE_ZXING_PACKAGE = 'com.google.zxing.client.android';
  134. begin
  135. Result := TJIntent.JavaClass.init(StringToJString(GOOGLE_ZXING));
  136. Result.setPackage(StringToJString(GOOGLE_ZXING_PACKAGE));
  137. end;
  138.  
  139. function TFrmMain.HandleAppEvent(AAppEvent: TApplicationEvent;
  140. AContext: TObject): Boolean;
  141. var
  142. LResult: string;
  143. begin
  144. if FZXingCalled and (AAppEvent = TApplicationEvent.aeBecameActive) then
  145. begin
  146. LResult := FClipboardService.GetClipboard.ToString;
  147. if LResult.IsEmpty then
  148. ShowInfo('扫描取消')
  149. else
  150. ShowInfo(LResult);
  151. ClipboardBack;
  152. FZXingCalled := False;
  153. end;
  154. Result := True;
  155. end;
  156.  
  157. function TFrmMain.IsIntentCallable(const AIntent: JIntent): Boolean;
  158. var
  159. LJPackageManager: JPackageManager;
  160. begin
  161. Result := False;
  162. if Assigned(AIntent) then
  163. begin
  164. LJPackageManager := SharedActivityContext.getPackageManager;
  165. Result := LJPackageManager.queryIntentActivities(AIntent,
  166. TJPackageManager.JavaClass.MATCH_DEFAULT_ONLY).size <> ;
  167. end;
  168. end;
  169.  
  170. procedure TFrmMain.OpenURL(const AURL: string);
  171. var
  172. LIntent: JIntent;
  173. begin
  174. LIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
  175. TJnet_Uri.JavaClass.parse(StringToJString(AURL)));
  176. SharedActivity.startActivity(LIntent);
  177. end;
  178.  
  179. procedure TFrmMain.SBTitleClick(Sender: TObject);
  180. begin
  181. OpenURL('http://code.google.com/p/zxing/downloads/list');
  182. end;
  183.  
  184. procedure TFrmMain.ShowInfo(const AInfo: string);
  185. begin
  186. Memo1.Text := AInfo;
  187. end;
  188.  
  189. end.

Delphi XE5 Android 调用 Google ZXing的更多相关文章

  1. delphi xe5 android 调用照相机获取拍的照片

    本篇文章我们来看一下delphi xe5 在android程序里怎样启动照相机并获取所拍的照片,本代码取自xe自带打sample,路径为: C:\Users\Public\Documents\RAD ...

  2. Delphi XE5 Android 调用手机震动

    uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array of Int6 ...

  3. Delphi XE5 Android 调用手机震动(通过JObject测试是否支持震动)

    源码如下: uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array o ...

  4. Delphi Android 将Google ZXing 整合(调用Jar文件)

    前篇文章介绍了在delphi App(以下简称App)中可使用intent来调用Google ZXing 条码扫描器(以下简称zx),其各有优缺点,优点是我们不需关注zx本身的细节,只需调用其接口即可 ...

  5. 学习使用Delphi for android 调用Java类库

    http://blog.csdn.net/laorenshen/article/details/41148253 学习使用Delphi for android 调用Java类库 2014-11-15 ...

  6. Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果

      Android 高手进阶(21)  版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处:http://blog.csdn.net/xiaanming/article/detail ...

  7. 【转】Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果--不错

    原文网址:http://blog.csdn.net/xiaanming/article/details/10163203 转载请注明出处:http://blog.csdn.net/xiaanming/ ...

  8. delphi xe5 android iny绿色版+最新SDK/NDK安装方法

    转自: http://bbs.2ccc.com/topic.asp?topicid=438595 首先感谢iny的绿色版,因为我的精简Win7 32位安装原版镜像4.63G过程正常,但是编译出错,后来 ...

  9. Delphi XE5 Android 运行黑屏卡死的解决方法

    1. 确保正确安装Android SDK: 开始菜单 > 所有程序 > Embarcadero RAD Studio XE5 > > Android Tools > 打开 ...

随机推荐

  1. 『Python CoolBook』C扩展库_其六_线程

    GIL操作 想让C扩展代码和Python解释器中的其他进程一起正确的执行, 那么你就需要去释放并重新获取全局解释器锁(GIL). 在Python接口封装中去释放并重新获取全局解释器锁(GIL),此时本 ...

  2. 原生JS获取DOM 节点到浏览器顶部的距离或者左侧的距离

    关于js获取dom 节点到浏览器顶/左部的距离,Jquery里面有封装好的offset().top/offset().left,只到父级的顶/左部距离position().top/position() ...

  3. 【其他】【http】【1】HTTP状态码

    一些常见的状态码: 200 - 服务器成功返回网页 400 - 错误请求 404 - 请求的网页不存在 500 - 服务器内部错误 503 - 服务器超时 状态码大全: 1xx(临时响应)表示临时响应 ...

  4. js禁止页面滚动

    开发移动端页面的时候有一个很比较常见的需求,在出现弹窗时,禁止滑动弹窗后面的主体页面.如何实现呢,往下看 js实现整个页面禁止滚动: document.body.addEventListener('t ...

  5. Android动画-View动画

    View动画 Android动画分为三类:View动画,帧动画,和属性动画.帧动画也是View动画的一种. View动画的作用对象是View,之所以强调这一点是因为其作用对象有别于Android的另一 ...

  6. DOM获取元素的方法

    DOM:document object module 文档对象模型 DOM就是描述整个html页面中节点关系的图谱,如下图. 1,通过ID,获取页面中元素的方法:(上下文必须是document) do ...

  7. 2.4 利用FTP服务器下载和上传目录

    利用FTP服务器下载目录 import os,sys from ftplib import FTP from mimetypes import guess_type nonpassive = Fals ...

  8. cocoa pods自己的笔记

    备注:这里只是个人的观点,有的地方也是copy,多多指教,个人笔记,有侵犯你们版权的地方还望海涵!!! 卡主不动 安装流程:http://www.tuicool.com/articles/qaMfuy ...

  9. admin 后台

    https://segmentfault.com/a/1190000015835976#articleHeader3https://github.com/PanJiaChen/vue-element- ...

  10. java类的高级概念