Zxing scan code example

Zxing scan code example

Source code introduction

An example of Zxing scanning code. There are some bugs in the program, and it will freeze if it is not scanned for a long time.
Source code running screenshot

Source code snippet:

  1. public   class MainActivity extends Activity{
  2.   
  3. private Button button;
  4. private TextView resultText;
  5. private   final   static   int SCANNIN_GREQUEST_CODE = 1 ;
  6.       
  7. @Override  
  8. protected   void onCreate(Bundle savedInstanceState) {
  9. super .onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_main);
  11.           
  12. resultText = (TextView) this .findViewById(R.id.result);
  13.           
  14. button = (Button) this .findViewById(R.id.scanCodeButton);
  15. button.setOnClickListener( new OnClickListener(){
  16. @Override  
  17. public   void onClick(View v) {
  18. Intent intent = new Intent();
  19. intent.setClass(MainActivity. this , CaptureActivity. class );
  20. intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  21. startActivityForResult(intent, SCANNIN_GREQUEST_CODE);
  22. }
  23. });
  24. }
  25.   
  26. @Override  
  27. protected   void onActivityResult( int requestCode, int resultCode, Intent data) {
  28. super .onActivityResult(requestCode, resultCode, data);
  29. switch (requestCode){
  30. case SCANNIN_GREQUEST_CODE:
  31. if (resultCode == RESULT_OK){
  32. Bundle bundle = data.getBundleExtra( "bundle" );
  33. String resultString = bundle.getString( "result" );
  34. resultText.setText(resultString);
  35. }
  36. break ;
  37. }
  38. }
  39.   
  40.       
  41. }

Source code link: http://download..com/data/1983052

<<:  PagerAdapter paging image and text view, can slide left and right

>>:  Context-Menu.Android

Recommend

How do brands plan their Double Eleven marketing?

The second half of every year is a carnival for e...

Apple's decline

"Is there any signal?" two Apple users ...

Zhou Chenchen: "Performance Testing"

Let’s talk about performance testing in detail. Te...

The marketing logic followed by Apple and Huawei (focus on 3 key points)

The topic I will share today is "Cognitive M...

The most powerful bird of prey turns out to be a big bald man?

Around 3500 BC, a large number of humans migrated...

IDC: Enterprise WLAN market to decline 12.7% year-over-year in 2024

The global enterprise wireless LAN (WLAN) market ...

Why is the champion single product "leek box" so delicious~~

Audit expert: Wang Guoyi Postdoctoral fellow in N...

The 10 most common problems on Android

[[156039]] Here are the most common React native ...

Improve problem-solving skills through psychological knowledge

[[143040]] Preface Software development work can ...

Tik Tok brand self-broadcasting channel building strategy!

My core point is that brand live streaming channe...