Delphi10.2东京AndroidonActivityResult商米扫码
Delphi 10.2 Tokyo Android onActivityResult Sunmi Code Scanning
我需要将扫码集成到应用中
(https://docs.sunmi.com/htmls/Scan%20code%20driver.html)
申请于 Delphi 10.2 东京
当我按下按钮时,我使用此代码,扫描仪打开并读取代码
procedure TfSkenKarta.Button1Click(Sender: TObject);
var
Intent: JIntent;
ReqCode : Integer;
begin
ReqCode := SCAN_REQUEST_CODE;
FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification, HandleActivityMessage);
Intent := TJIntent.Create;
Intent.setPackage(StringToJString('com.sunmi.sunmiqrcodescanner'));
Intent.setClassName(StringToJString('com.sunmi.sunmiqrcodescanner'),StringToJString('com.sunmi.sunmiqrcodescanner.activity.ScanActivity'));
Intent.putExtra(StringToJString('PLAY_SOUND'), true);
TAndroidHelper.Activity.startActivityForResult(Intent, SCAN_REQUEST_CODE);
end;
我正在使用这个数据检索
procedure TfSkenKarta.HandleActivityMessage(const Sender: TObject; const M: TMessage);
begin
if M is TMessageResultNotification then
OnActivityResult(
TMessageResultNotification(M).RequestCode,
TMessageResultNotification(M).ResultCode,
TMessageResultNotification(M).Value);
end;
function TfSkenKarta.OnActivityResult(RequestCode, ResultCode: Integer;
Data: JIntent): Boolean;
var ret:JArrayList;
LScanContent, LScanFormat: string;
begin
Result := False;
TMessageManager.DefaultManager.Unsubscribe(TMessageResultNotification, FMessageSubscriptionID);
FMessageSubscriptionID := 0;
if RequestCode = SCAN_REQUEST_CODE then
begin
if ResultCode = TJActivity.JavaClass.RESULT_OK then
begin
Result := True;
if Assigned(Data) then
begin
LScanContent := JStringToString(Data.getStringExtra(StringToJString('VALUE')));
LScanFormat := JStringToString(Data.getStringExtra(StringToJString('TYPE')));
TThread.Synchronize(nil,
procedure
begin
ShowmessageToast('tu sam TThreadTThread :LScanContent:' +LScanContent + ' LScanFormat:: ' + LScanFormat, TJToast.JavaClass.LENGTH_LONG);
end
);
end;
end
end;
end;
java 例子
/**
*
*Creating a Intent at where you want start scanner, calling the scanner by startActiityForResult();
*/
Intent intent = new Intent("com.summi.scan");
intent.setPackage("com.sunmi.sunmiqrcodescanner");
/**
* The method is the same function as above
*Intent intent = new Intent("com.summi.scan");
*intent.setClassName("com.sunmi.sunmiqrcodescanner", "com.sunmi.sunmiqrcodescanner.activity.ScanActivity");
*/
/**
//there is also some options item about the scanner module, you can transfer parameters to control some settings, each item has a defaut status,transform parameter is not necessary,
intent.putExtra("CURRENT_PPI", 0X0003);//The current preview resolution ,PPI_1920_1080 = 0X0001;PPI_1280_720 = 0X0002;PPI_BEST = 0X0003;
intent.putExtra("PLAY_SOUND", true);// Prompt tone after scanning ,default true
intent.putExtra("PLAY_VIBRATE", false);//vibrate after scanning,default false,only support M1 right now.
intent.putExtra("IDENTIFY_INVERSE_QR_CODE", true);//Whether to identify inverse code
intent.putExtra("IDENTIFY_MORE_CODE", false);// Whether to identify several code,default false
intent.putExtra("IS_SHOW_SETTING", true);// Wether display set up button at the top-right corner,default true
intent.putExtra("IS_SHOW_ALBUM", true);// Wether display album,default true
*/
startActivityForResult(intent, START_SCAN);
/////
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && data != null) {
Bundle bundle = data.getExtras();
ArrayList<HashMap<String, String>> result = (ArrayList<HashMap<String, String>>) bundle
.getSerializable("data");
Iterator<HashMap<String, String>> it = result.iterator();
while (it.hasNext()) {
HashMap<String, String> hashMap = it.next();
Log.i("sunmi", hashMap.get("TYPE"));//this is the type of the code
Log.i("sunmi", hashMap.get("VALUE"));//this is the result of the code
}
}
super.onActivityResult(requestCode, resultCode, data);
}
但无论如何我都无法阅读扫描的代码。
我正在取回我的空数据
鉴于 Java 示例,我得出以下结论:
uses
Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os, Androidapi.Helpers;
...
var
LBundle: JBundle;
LMap: JMap;
LIterator: JIterator;
LType, LValue: string;
begin
LBundle := Data.getExtras;
LIterator := TJArrayList.Wrap(LBundle.getSerializable(StringToJString('data'))).iterator;
while LIterator.hasNext do
begin
LMap := TJMap.Wrap(JObjectToID(LIterator.next));
LType := JStringToString(TJString.Wrap(JObjectToID(LMap.get(StringToJString('TYPE')))));
LValue := JStringToString(TJString.Wrap(JObjectToID(LMap.get(StringToJString('VALUE')))));
end;
end;
很遗憾,我没有商米,无法测试,所以请记住这一点
我需要将扫码集成到应用中 (https://docs.sunmi.com/htmls/Scan%20code%20driver.html) 申请于 Delphi 10.2 东京
当我按下按钮时,我使用此代码,扫描仪打开并读取代码
procedure TfSkenKarta.Button1Click(Sender: TObject);
var
Intent: JIntent;
ReqCode : Integer;
begin
ReqCode := SCAN_REQUEST_CODE;
FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification, HandleActivityMessage);
Intent := TJIntent.Create;
Intent.setPackage(StringToJString('com.sunmi.sunmiqrcodescanner'));
Intent.setClassName(StringToJString('com.sunmi.sunmiqrcodescanner'),StringToJString('com.sunmi.sunmiqrcodescanner.activity.ScanActivity'));
Intent.putExtra(StringToJString('PLAY_SOUND'), true);
TAndroidHelper.Activity.startActivityForResult(Intent, SCAN_REQUEST_CODE);
end;
我正在使用这个数据检索
procedure TfSkenKarta.HandleActivityMessage(const Sender: TObject; const M: TMessage);
begin
if M is TMessageResultNotification then
OnActivityResult(
TMessageResultNotification(M).RequestCode,
TMessageResultNotification(M).ResultCode,
TMessageResultNotification(M).Value);
end;
function TfSkenKarta.OnActivityResult(RequestCode, ResultCode: Integer;
Data: JIntent): Boolean;
var ret:JArrayList;
LScanContent, LScanFormat: string;
begin
Result := False;
TMessageManager.DefaultManager.Unsubscribe(TMessageResultNotification, FMessageSubscriptionID);
FMessageSubscriptionID := 0;
if RequestCode = SCAN_REQUEST_CODE then
begin
if ResultCode = TJActivity.JavaClass.RESULT_OK then
begin
Result := True;
if Assigned(Data) then
begin
LScanContent := JStringToString(Data.getStringExtra(StringToJString('VALUE')));
LScanFormat := JStringToString(Data.getStringExtra(StringToJString('TYPE')));
TThread.Synchronize(nil,
procedure
begin
ShowmessageToast('tu sam TThreadTThread :LScanContent:' +LScanContent + ' LScanFormat:: ' + LScanFormat, TJToast.JavaClass.LENGTH_LONG);
end
);
end;
end
end;
end;
java 例子
/**
*
*Creating a Intent at where you want start scanner, calling the scanner by startActiityForResult();
*/
Intent intent = new Intent("com.summi.scan");
intent.setPackage("com.sunmi.sunmiqrcodescanner");
/**
* The method is the same function as above
*Intent intent = new Intent("com.summi.scan");
*intent.setClassName("com.sunmi.sunmiqrcodescanner", "com.sunmi.sunmiqrcodescanner.activity.ScanActivity");
*/
/**
//there is also some options item about the scanner module, you can transfer parameters to control some settings, each item has a defaut status,transform parameter is not necessary,
intent.putExtra("CURRENT_PPI", 0X0003);//The current preview resolution ,PPI_1920_1080 = 0X0001;PPI_1280_720 = 0X0002;PPI_BEST = 0X0003;
intent.putExtra("PLAY_SOUND", true);// Prompt tone after scanning ,default true
intent.putExtra("PLAY_VIBRATE", false);//vibrate after scanning,default false,only support M1 right now.
intent.putExtra("IDENTIFY_INVERSE_QR_CODE", true);//Whether to identify inverse code
intent.putExtra("IDENTIFY_MORE_CODE", false);// Whether to identify several code,default false
intent.putExtra("IS_SHOW_SETTING", true);// Wether display set up button at the top-right corner,default true
intent.putExtra("IS_SHOW_ALBUM", true);// Wether display album,default true
*/
startActivityForResult(intent, START_SCAN);
/////
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && data != null) {
Bundle bundle = data.getExtras();
ArrayList<HashMap<String, String>> result = (ArrayList<HashMap<String, String>>) bundle
.getSerializable("data");
Iterator<HashMap<String, String>> it = result.iterator();
while (it.hasNext()) {
HashMap<String, String> hashMap = it.next();
Log.i("sunmi", hashMap.get("TYPE"));//this is the type of the code
Log.i("sunmi", hashMap.get("VALUE"));//this is the result of the code
}
}
super.onActivityResult(requestCode, resultCode, data);
}
但无论如何我都无法阅读扫描的代码。 我正在取回我的空数据
鉴于 Java 示例,我得出以下结论:
uses
Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.JavaTypes, Androidapi.JNI.Os, Androidapi.Helpers;
...
var
LBundle: JBundle;
LMap: JMap;
LIterator: JIterator;
LType, LValue: string;
begin
LBundle := Data.getExtras;
LIterator := TJArrayList.Wrap(LBundle.getSerializable(StringToJString('data'))).iterator;
while LIterator.hasNext do
begin
LMap := TJMap.Wrap(JObjectToID(LIterator.next));
LType := JStringToString(TJString.Wrap(JObjectToID(LMap.get(StringToJString('TYPE')))));
LValue := JStringToString(TJString.Wrap(JObjectToID(LMap.get(StringToJString('VALUE')))));
end;
end;
很遗憾,我没有商米,无法测试,所以请记住这一点