1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Scan Barcodes on Android with Delphi XE5+

Discussion in 'Delphi Programming' started by AdminDF, Jan 8, 2015.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Embarcadero's shiny new Delphi XE5 Mobile Module seems to be lacking something rather important to those of us wishing to scan barcodes on Android. Although it is fairly simple to use intents to start up other Android activities, with their required parameters, there seems to be no way to register a callback function to receive results. This is my, rather inelegant, workaround whilst waiting for that deficiency to be fixed. I have currently only tried using the free, open source, ZXing library available on Google Play. See the ZXing Google Code page here https://code.google.com/p/zxing/ for more info the library and licensing. I'm assuming a similar state of ignorance to the one I was in starting out with XE5, also a form containing a button, an editcontrol and a timer. The following needs to be present in the main form 



    Code:
    Uses FMX.platform, fmx.helpers.android, androidapi.JNI.GraphicsContentViewText, androidapi.jni.JavaTypes;  

    the first module is required for clipboard access, the others for the JNI (Java Native Interface) in the forms private declarations 



    Code:
    ClipService: IFMXClipboardService;  
    Elapsed: integer;
    
     
    in the FormCreate event 



    Code:
    if not TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, IInterface(ClipService)) then      
    ClipService := nil; Elapsed := 0;  
    

    gives the app access to the clipboard The button's onclick event 



    Code:
    procedure Tform1.Button1click(sender: Tobject); var   intent: jintent; begin   if assigned(ClipService) then    
    begin      
    clipservice.SetClipboard('nil');      
    intent := tjintent.Create;     intent.setAction(stringtojstring('com.google.zxing.client.android.SCAN'));     intent.putExtra(tjintent.JavaClass.EXTRA_TEXT,       stringtojstring('"SCAN_MODE", "CODE_39"'));      
    sharedactivity.startActivityForResult(intent,0); Elapsed := 0;      
    timer1.Enabled := true;    
    end;  
    end;  
    

    the intent.putExtra is optional, if used it narrows the range of codes that ZXing looks for. The clipboard value can be set to anything you like, it’s only there to check for the clipboard changing. The variable Elapsed is there to provide a timeout in case the user cancels the scan. I have my timer set to 500ms intervals which seems okay in practice. The timer event looks like this 



    Code:
    procedure TForm1.Timer1Timer(Sender: TObject);  
    begin  
    if (ClipService.GetClipboard.ToString <> 'nil') then  
    begin  
    timer1.Enabled := false;  
    Elapsed := 0;      
    edit1.Text := ClipService.GetClipboard.ToString;    
    end else  
    begin  
    if Elapsed >9 then  
    begin  
    timer1.Enabled := false;  
    Elapsed := 0;  
    end else Elapsed := Elapsed +1;  
    end;  
    end;  
    

    That’s it! 

    Componenet



    Code:
    http://zbar.sourceforge.net/
    Link:


    Code:
    http://john.whitham.me.uk/xe5/
    
     
  2. thotsaphon34
    Online

    thotsaphon34 Guest

    RE:

    Don't Work
     
  3. haneol
    Online

    haneol Guest

    [quote pid=73649 dateline=1420709213]Thanks[/quote]
     
  4. jcpozi555
    Online

    jcpozi555 Guest

  5. rikk
    Online

    rikk Guest

    Thank you
     
  6. russocorp
    Online

    russocorp DF Junior

    testing
     
  7. server
    Online

    server Guest

    RE:

    thank you
     

Share This Page