Delphi XE5 Android 调用 Google ZXing
- {
- Google ZXing Call demo
- Delphi Version: Delphi XE5 Version 19.0.13476.4176
- By: flcop(zylove619@hotmail.com)
- }
- 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.StdCtrls,
- FMX.Layouts, FMX.Memo,
- System.Rtti,
- FMX.Helpers.Android,
- Androidapi.JNI.Net,
- Androidapi.JNI.GraphicsContentViewText,
- Androidapi.JNI.JavaTypes,
- FMX.platform,
- FMX.Platform.Android;
- type
- TFrmMain = class(TForm)
- Memo1: TMemo;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- PanelOpt: TPanel;
- Panel2: TPanel;
- SBTitle: TSpeedButton;
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure SBTitleClick(Sender: TObject);
- private
- { Private declarations }
- FClipboardService: IFMXClipboardService;
- FClipboardValue: TValue;
- FZXingCalled: Boolean;
- procedure CallZXing(const ACodeMode: string);
- function IsIntentCallable(const AIntent: JIntent): Boolean;
- function GetZXingIntent: JIntent;
- procedure ClipboardSave;
- procedure ClipboardBack;
- procedure ShowInfo(const AInfo: string);
- function HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
- procedure CheckEnvironment;
- procedure OpenURL(const AURL: string);
- public
- { Public declarations }
- end;
- var
- FrmMain: TFrmMain;
- implementation
- {$R *.fmx}
- const
- CodeModes: array[..] of string = ('PRODUCT_MODE', 'QR_CODE_MODE', 'SCAN_MODE');
- procedure TFrmMain.Button1Click(Sender: TObject);
- begin
- // , ,
- CallZXing(CodeModes[TButton(Sender).Tag]);
- end;
- procedure TFrmMain.CallZXing(const ACodeMode: string);
- var
- LIntent: JIntent;
- begin
- ClipboardSave;
- FClipboardService.SetClipboard('');
- LIntent := GetZXingIntent();
- LIntent.putExtra(StringToJString('SCAN_MODE'), StringToJString(ACodeMode));
- SharedActivity.startActivityForResult(LIntent, );
- FZXingCalled := True;
- end;
- procedure TFrmMain.CheckEnvironment;
- var
- LFMXApplicationEventService: IFMXApplicationEventService;
- LIsZXingCallable: Boolean;
- LStr: string;
- begin
- if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService,
- IInterface(LFMXApplicationEventService)) then
- LFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
- else
- LStr := '调用失败,不支持IFMXApplicationEventService!';
- if not TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService,
- IInterface(FClipboardService)) then
- LStr := LStr + sLineBreak + '调用失败, 不支持IFMXClipboardService!';
- LIsZXingCallable := IsIntentCallable(GetZXingIntent);
- if not LIsZXingCallable then
- begin
- SBTitle.Text := '点我去ZXing下载页...';
- SBTitle.OnClick := SBTitleClick;
- LStr := LStr + sLineBreak + '未发现ZXing, 请安装ZXing后重新启动本程序';
- end else
- SBTitle.Text := 'Google ZXing Call';
- ShowInfo(LStr.Trim);
- PanelOpt.Enabled := Assigned(LFMXApplicationEventService) and
- Assigned(FClipboardService) and LIsZXingCallable;
- end;
- procedure TFrmMain.ClipboardBack;
- begin
- FClipboardService.SetClipboard(FClipboardValue);
- end;
- procedure TFrmMain.ClipboardSave;
- begin
- FClipboardValue := FClipboardService.GetClipboard;
- end;
- procedure TFrmMain.FormCreate(Sender: TObject);
- begin
- CheckEnvironment;
- end;
- function TFrmMain.GetZXingIntent: JIntent;
- const
- GOOGLE_ZXING = 'com.google.zxing.client.android.SCAN';
- GOOGLE_ZXING_PACKAGE = 'com.google.zxing.client.android';
- begin
- Result := TJIntent.JavaClass.init(StringToJString(GOOGLE_ZXING));
- Result.setPackage(StringToJString(GOOGLE_ZXING_PACKAGE));
- end;
- function TFrmMain.HandleAppEvent(AAppEvent: TApplicationEvent;
- AContext: TObject): Boolean;
- var
- LResult: string;
- begin
- if FZXingCalled and (AAppEvent = TApplicationEvent.aeBecameActive) then
- begin
- LResult := FClipboardService.GetClipboard.ToString;
- if LResult.IsEmpty then
- ShowInfo('扫描取消')
- else
- ShowInfo(LResult);
- ClipboardBack;
- FZXingCalled := False;
- end;
- Result := True;
- end;
- function TFrmMain.IsIntentCallable(const AIntent: JIntent): Boolean;
- var
- LJPackageManager: JPackageManager;
- begin
- Result := False;
- if Assigned(AIntent) then
- begin
- LJPackageManager := SharedActivityContext.getPackageManager;
- Result := LJPackageManager.queryIntentActivities(AIntent,
- TJPackageManager.JavaClass.MATCH_DEFAULT_ONLY).size <> ;
- end;
- end;
- procedure TFrmMain.OpenURL(const AURL: string);
- var
- LIntent: JIntent;
- begin
- LIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
- TJnet_Uri.JavaClass.parse(StringToJString(AURL)));
- SharedActivity.startActivity(LIntent);
- end;
- procedure TFrmMain.SBTitleClick(Sender: TObject);
- begin
- OpenURL('http://code.google.com/p/zxing/downloads/list');
- end;
- procedure TFrmMain.ShowInfo(const AInfo: string);
- begin
- Memo1.Text := AInfo;
- end;
- end.
Delphi XE5 Android 调用 Google ZXing的更多相关文章
- delphi xe5 android 调用照相机获取拍的照片
本篇文章我们来看一下delphi xe5 在android程序里怎样启动照相机并获取所拍的照片,本代码取自xe自带打sample,路径为: C:\Users\Public\Documents\RAD ...
- Delphi XE5 Android 调用手机震动
uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array of Int6 ...
- Delphi XE5 Android 调用手机震动(通过JObject测试是否支持震动)
源码如下: uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array o ...
- Delphi Android 将Google ZXing 整合(调用Jar文件)
前篇文章介绍了在delphi App(以下简称App)中可使用intent来调用Google ZXing 条码扫描器(以下简称zx),其各有优缺点,优点是我们不需关注zx本身的细节,只需调用其接口即可 ...
- 学习使用Delphi for android 调用Java类库
http://blog.csdn.net/laorenshen/article/details/41148253 学习使用Delphi for android 调用Java类库 2014-11-15 ...
- Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果
Android 高手进阶(21) 版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处:http://blog.csdn.net/xiaanming/article/detail ...
- 【转】Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果--不错
原文网址:http://blog.csdn.net/xiaanming/article/details/10163203 转载请注明出处:http://blog.csdn.net/xiaanming/ ...
- delphi xe5 android iny绿色版+最新SDK/NDK安装方法
转自: http://bbs.2ccc.com/topic.asp?topicid=438595 首先感谢iny的绿色版,因为我的精简Win7 32位安装原版镜像4.63G过程正常,但是编译出错,后来 ...
- Delphi XE5 Android 运行黑屏卡死的解决方法
1. 确保正确安装Android SDK: 开始菜单 > 所有程序 > Embarcadero RAD Studio XE5 > > Android Tools > 打开 ...
随机推荐
- 『Python CoolBook』C扩展库_其六_线程
GIL操作 想让C扩展代码和Python解释器中的其他进程一起正确的执行, 那么你就需要去释放并重新获取全局解释器锁(GIL). 在Python接口封装中去释放并重新获取全局解释器锁(GIL),此时本 ...
- 原生JS获取DOM 节点到浏览器顶部的距离或者左侧的距离
关于js获取dom 节点到浏览器顶/左部的距离,Jquery里面有封装好的offset().top/offset().left,只到父级的顶/左部距离position().top/position() ...
- 【其他】【http】【1】HTTP状态码
一些常见的状态码: 200 - 服务器成功返回网页 400 - 错误请求 404 - 请求的网页不存在 500 - 服务器内部错误 503 - 服务器超时 状态码大全: 1xx(临时响应)表示临时响应 ...
- js禁止页面滚动
开发移动端页面的时候有一个很比较常见的需求,在出现弹窗时,禁止滑动弹窗后面的主体页面.如何实现呢,往下看 js实现整个页面禁止滚动: document.body.addEventListener('t ...
- Android动画-View动画
View动画 Android动画分为三类:View动画,帧动画,和属性动画.帧动画也是View动画的一种. View动画的作用对象是View,之所以强调这一点是因为其作用对象有别于Android的另一 ...
- DOM获取元素的方法
DOM:document object module 文档对象模型 DOM就是描述整个html页面中节点关系的图谱,如下图. 1,通过ID,获取页面中元素的方法:(上下文必须是document) do ...
- 2.4 利用FTP服务器下载和上传目录
利用FTP服务器下载目录 import os,sys from ftplib import FTP from mimetypes import guess_type nonpassive = Fals ...
- cocoa pods自己的笔记
备注:这里只是个人的观点,有的地方也是copy,多多指教,个人笔记,有侵犯你们版权的地方还望海涵!!! 卡主不动 安装流程:http://www.tuicool.com/articles/qaMfuy ...
- admin 后台
https://segmentfault.com/a/1190000015835976#articleHeader3https://github.com/PanJiaChen/vue-element- ...
- java类的高级概念