Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to scan and generate QR Code in Android

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report