Delphi 10.2 Tokyo Android onActivityResult Sunmi Code Scanning

by sale2211   Last Updated February 06, 2019 21:26 PM - source

I need to integrate Code Scanning into the application (https://docs.sunmi.com/htmls/Scan%20code%20driver.html) The application was made in Delphi 10.2 Tokyo

When I press the button, I use this code and the scaner opens and reads the code

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;

I'm using this data retrieval

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 example

/**

    * 

    *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);

but I can not read the scanned code anyway. I'm getting my empty data back



Related Questions



Old / dark dialog boxes when using TStyleBook

Updated December 02, 2017 18:26 PM


How to properly clean an Android listener?

Updated February 26, 2019 10:26 AM

Images not showing correctly on android

Updated September 05, 2019 01:26 AM