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 > 打开 ...
随机推荐
- Token国内地铁使用城市
天津 广州 深圳 南京 武汉 台北 高雄
- fcn+caffe+siftflow实验记录
环境搭建: vs2013,编译caffe工程,cuda8.0,cudnn5.1,python2.7. 还需要安装python的一些包.Numpy+mkl scipy matplotlib sci ...
- LeetCode--023--合并K个排序链表
合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6 ] 输出: 1-&g ...
- Windows 2003 Server R2 x64 IIS6.0 eWebEditor无法显示的问题
64位的操作系统安装成功后,一般IIS也是默认的64位的解析,所以将程序放到64位操作系统上的时候,会出现IIS错误,解决方案也非常简单,将64位IIS停止,启动32位的就可以了. 输入以下命令启用 ...
- zend cache使用
require_once 'Zend/Cache.php';//引用文件$frontendOptions = array( 'lifeTime' => 60, // cache lifetime ...
- 添加浏览器back操作时的响应事件
https://blog.csdn.net/xcqingfeng/article/details/70800118 $(function(){ pushHistory(); window.addEve ...
- FileReader字符的读出
1.fileReader是字符的读出,只能读文件. 2.在读取文件的之前,该文件必须存在. 3.int reader();一次读取一个字符,返回的该字符的码值,如果想要返回字符,直接进行强转char ...
- Quartz定时器+Spring + @Autowired注入 空指针异常
在Quartz的定时方法里引用@Autowired注入Bean,会报空指针错误 解决办法: 第一种方法:(推荐,简单,亲测可行) 使用@Resource(name="指定要注入的Bean&q ...
- Maximum Average Subarray
Given an array with positive and negative numbers, find the maximum average subarray which length sh ...
- 用setTimeout模拟setInterval的功能
偶然看到这个题目,稍微写了下,做个笔记,不足之处请指正 //用setTimeout模仿setInterval var MyInterVal = function(fun,tm){ if(this == ...