1

我使用 Delphi XE6 创建了一个 Android 应用程序,并使用在 Internet 上找到的代码连接到 ZXing BarCode Scanner。

在仅使用此代码的新项目中,一切正常!

如果我添加几个TabControl, ToolBar, Label,和其他标准组件,我会遇到这种情况EditButton

  1. ZXing 正常启动,如果我定期将条形码扫描回我的应用程序。
  2. 如果我用硬件后退按钮关闭 ZXing,ZXing 会关闭,但应用程序会因黑屏而冻结。

通过调试,应用程序似乎并没有停止。返回代码被更正,流程一直持续到结束,没有给出任何错误。

调用代码是:

function TZXing.ZXingScan: Boolean;
var
  Intent: JIntent;
  ResolveInfo: JResolveInfo;
begin
  Intent := TJIntent.JavaClass.init( StringToJString( 'com.google.zxing.client.android.SCAN' ) );
  Intent.setPackage( StringToJString( 'com.google.zxing.client.android' ) );
  Intent.putExtra( StringToJString( 'SAVE_HISTORY' ), False );
  ResolveInfo := SharedActivity.getPackageManager.resolveActivity( Intent, 0 );
  Result := ResolveInfo <> nil;
  if Result then
    SharedActivity.startActivityForResult( Intent, 0 );
end;

回调过程代码为:

procedure TZXing.OnZXingResult( RequestCode, ResultCode: Integer; Data: JIntent );
begin
  TMessageManager.DefaultManager.Unsubscribe( TMessageResultNotification, FMessageSubscriptionID );
  FMessageSubscriptionID := 0;
  if ( RequestCode = 0 ) and Assigned( FResultProcedure ) then
  begin
    if ResultCode = TJActivity.JavaClass.RESULT_OK then
    begin
      if Assigned( Data ) then
        Result := ( OK, JStringToString( Data.getStringExtra( StringToJString( 'SCAN_RESULT_FORMAT') ) ), JStringToString( Data.getStringExtra( StringToJString( 'SCAN_RESULT' ) ) ) )
      else
        Result := ERROR;
    end else if ResultCode = TJActivity.JavaClass.RESULT_CANCELED then
      Result := CANCELED;
  end;
end;

我已经尝试了所有方法并尝试了所有方法,但我找不到解决方案。

4

2 回答 2

1

我认为问题可能在于您处理后退按钮的方法。这是我的后退按钮代码:

procedure TFrmBezoekverslag.FormKeyUp(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
var
  FService: IFMXVirtualKeyboardService;
begin
  if Key = vkHardwareBack then
  begin
      TPlatformServices.Current.SupportsPlatformService
        (IFMXVirtualKeyboardService, IInterface(FService));
      if (FService <> nil) and (TVirtualKeyboardState.Visible
        in FService.VirtualKeyBoardState) then
      begin
        // Back button pressed, keyboard visible, so do nothing...
      end
      else
      begin
        // Back button pressed, keyboard not visible or not supported on this platform
        // Here you handle the code too close ZXING
        Key := 0; //If you don't want the form too close you need too add key=0
      end;
  end;
end;

如果这没有帮助,问题可能在 formClose 方法中的某个地方,如果你有的话。

于 2014-08-08T12:03:58.657 回答
0

最有可能的是,您的结果代码是null被调用Activity者必须明确设置的。尝试覆盖onBackPressed()将结果代码设置为“取消”,然后再调用super.

于 2014-06-03T16:36:14.630 回答