{
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. web前端性能优化总结一

    转自:http://www.2cto.com/kf/201604/498725.html 网站的划分一般为二:前端和后台.我们可以理解成后台是用来实现网站的功能的,比如:实现用户注册,用户能够为文章发 ...

  2. eclipse工具类及插件(svn的安装)

    (摘抄原文)https://blog.csdn.net/nzzl54/article/details/80768838

  3. VS--------实用快捷键

    Ctrl + M + O : 折叠所有方法 Ctrl + Tab: 切换不同窗口 ------------------------------开发--------------------------- ...

  4. History of program(1950-2020)

    1957年 约翰·巴科斯(John Backus)创建了是全世界第一套高阶语言:FORTRAN. John Backus 1959年 葛丽丝·霍普(Grace Hopper)创造了现代第一个编译器A- ...

  5. java中的线程问题(二)——线程的创建和用法。

    在java中一个类要当作线程来使用有两种方法. 1.继承Thread类,并重写run函数 2.实现Runnable接口,并重写run函数 因为java是单继承的,在某些情况下一个类可能已经继承了某个父 ...

  6. java中有关初始化的问题

    在类的内部,变量定义的先后顺序决定了初始化顺序,即使变量定义分散在方法定义之外,它们依旧会在任何方法(包括构造器)被调用之前得到初始化 其中初始化的顺序先是静态对象,其后是非静态对象 例如: clas ...

  7. FCC JS基础算法题(0):Reverse a String(翻转字符串)

    题目描述: 先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序,最后把数组转化成字符串.你的结果必须得是一个字符串. 算法: function reverseString(str) { ...

  8. 莫烦tensorflow(9)-Save&Restore

    import tensorflow as tfimport numpy as np ##save to file#rember to define the same dtype and shape w ...

  9. C# 图片处理方法 整理汇总

    /// <summary> /// 图片转为base64编码字符 /// </summary> /// <param name="path">图 ...

  10. jq 绑定事件和解绑事件

    <!DOCTYPE html><html><head> <script src="http://cdn.static.runoob.com/libs ...