{
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的更多相关文章

  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. linux软件管理之源码包管理

    源码包管理tarball ====================================================================================tar ...

  2. js中defer实现等文档加载完在执行脚本

    我们可以使用defer来实现类似window.onload的功能: <script src="../CGI-bin/delscript.js" defer></s ...

  3. pandas实现excel中的数据透视表和Vlookup函数功能

    在孩子王实习中做的一个小工作,方便整理数据. 目前这几行代码是实现了一个数据透视表和匹配的功能,但是将做好的结果写入了不同的excel中, 如何实现将结果连续保存到同一个Excel的同一个工作表中?还 ...

  4. 解决Docker容器时区不一致的问题

    查看linux系统时区和docker容器时区 date -R //查看linux主机时间和时区 date exec [container] date -R // 查看容器时间和时区 2者的时间差了8个 ...

  5. session和cookie的应用场景和区别

    cookie存于客户端,session存于服务器端. cookie的作用是与服务器进行交互,作为http规范的一部分存在,而web storage是为了在本地存储“数据”而生. cookie应用场景: ...

  6. Spring Boot + Spring Cloud 实现权限管理系统 权限控制(Shiro 注解)

    技术背景 当前,我们基于导航菜单的显示和操作按钮的禁用状态,实现了页面可见性和操作可用性的权限验证,或者叫访问控制.但这仅限于页面的显示和操作,我们的后台接口还是没有进行权限的验证,只要知道了后台的接 ...

  7. sublime3 前端个人常用插件及快捷键

    首先先介绍如何启用插件安装功能: 打开Sublime 3,然后按 ctrl+` 或者在View → Show Console 在打开的窗口里黏贴这个网站上的代码(注意: Sublime 2和3所黏贴的 ...

  8. python魔术方法(__init__,__call__,被双下划线包围的方法)

    转载link:http://pycoders-weekly-chinese.readthedocs.io/en/latest/issue6/a-guide-to-pythons-magic-metho ...

  9. VSTO:使用C#开发Excel、Word【13】

    应用程序对象的操作本章将介绍从Application对象开始的Excel对象模型中的一些主要对象. Excel对象模型中的主要对象有许多方法和属性,完全描述这些对象超出了本书的范围.相反,本章重点介绍 ...

  10. 用Python自动发送邮件

    用Python自动发送邮件     最近需要在服务器上处理一些耗时比较长的任务,因此想到利用python写一个自动发送邮件的脚本,在任务执行完毕后发送邮件通知我.以下代码以163邮箱为例: 开通163 ...