procedure TMainForm.BarcodeScannerButtonClick(Sender: TObject);
begin
FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification,
HandleActivityMessage);
LaunchQRScanner(ScanRequestCode);
end;
procedure TMainForm.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 TMainForm.OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent): Boolean;
var
ScanContent, ScanFormat: string;
begin
Result := False;
TMessageManager.DefaultManager.Unsubscribe(TMessageResultNotification, FMessageSubscriptionID);
FMessageSubscriptionID := 0;
// For more info see https://github.com/zxing/zxing/wiki/Scanning-Via-Intent
if RequestCode = ScanRequestCode then
begin
if ResultCode = TJActivity.JavaClass.RESULT_OK then
begin
if Assigned(Data) then
begin
ScanContent := JStringToString(Data.getStringExtra(StringToJString('SCAN_RESULT')));
ScanFormat := JStringToString(Data.getStringExtra(StringToJString('SCAN_RESULT_FORMAT')));
Toast(Format('Found %s format barcode:'#10'%s', [ScanFormat, ScanContent]), LongToast);
end;
end
else if ResultCode = TJActivity.JavaClass.RESULT_CANCELED then
begin
Toast('You cancelled the scan', ShortToast);
end;
Result := True;
end;
end;
At the top of the article there is also a link to a similar article for Delphi XE5.