Get the App
SLTechnology News&Howtos  ›  Development  › 

How to scan and generate QR Code in Android

Shulou Source: shulou.com Published: 2022-05-31 21:08:15 09月19日 Update

This article mainly introduces how to scan and generate QR code in Android, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to scan and generate QR code in Android. Let's take a look.

MainActivity.java

Public class MainActivity extends AppCompatActivity {private ImageView mImageView; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); Button button = findViewById (R.id.btn); mImageView = findViewById (R.id.img); button.setOnClickListener (new View.OnClickListener () {/ / Click the button to scan the QR code @ Override public void onClick (View view) {Intent intent = new Intent (MainActivity.this,CaptureActivity.class); startActivityForResult (intent,2) }});} @ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {super.onActivityResult (requestCode, resultCode, data); if (requestCode==200&& resultCode==RESULT_OK) {if (data input null) {String content = data.getStringExtra (Constant.CODED_CONTENT); if (TextUtils.isEmpty (content)) {Toast.makeText (MainActivity.this, "your input is empty!", Toast.LENGTH_SHORT). Show (); return } Bitmap logo = BitmapFactory.decodeResource (getResources (), R.mipmap.ic_launcher); try {Bitmap bitmap = CodeCreator.createQRCode (content, 400,400, logo); mImageView.setImageBitmap (bitmap);} catch (WriterException e) {e.printStackTrace ();} Toast.makeText (MainActivity.this, "scan" + content,Toast.LENGTH_SHORT). Show ();}

Activity.main.xml

Permissions required to be configured

Build.gradle

MinSdkVersion 16 / / configure 16 implementationists com.github.yuzhiqiang1993ZxingVOG 2.2.1' / / dependency

External build.gradle

Allprojects {repositories {google () jcenter () maven {url 'https://jitpack.io'} / / add this line of code}} this article on "how to scan and generate QR codes in Android" ends here. Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to scan and generate QR codes in Android". If you want to learn more, you are welcome to follow the industry information channel.

Tags: 2D QR code real generation knowledge content article configuration code value button easy to operate article easy to understand more permission look industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology Shulou Information OPPO Reno Microsoft