SoFunction
Updated on 2025-04-09

Android scan and generate QR codes

This article shares the specific code for Android scanning and generating QR codes for your reference. The specific content is as follows

public class MainActivity extends AppCompatActivity {

 private ImageView mImageView;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  (savedInstanceState);
  setContentView(.activity_main);

  Button button =findViewById();
  mImageView =findViewById();
  (new () { //Click the button to scan the QR code   @Override
   public void onClick(View view) {
    Intent intent = new Intent(,);


    startActivityForResult(intent,2);
   }
  });

 }

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  (requestCode, resultCode, data);
  if (requestCode==200&& resultCode==RESULT_OK){

   if (data!=null){
    String content = (Constant.CODED_CONTENT);
    if ((content)){

     (, "Your input is empty!", Toast.LENGTH_SHORT).show();
     return;

    }

    Bitmap logo = (getResources(), .ic_launcher);
    try {
     Bitmap bitmap = (content, 400, 400, logo);
     (bitmap);
    } catch (WriterException e) {
     ();
    }

    (,"scanning"+content,Toast.LENGTH_SHORT).show();


   }
  }
 }
}

< xmlns:andro
 xmlns:app="/apk/res-auto"
 xmlns:tools="/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity"
 android:orientation="vertical">

 <Button
  android:
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Scan"/>

 <ImageView
  android:
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  />

</>

Permissions required

<uses-permission android:name=""/>
 <uses-permission android:name=""></uses-permission>
 <uses-permission android:name="" />
 <uses-permission android:name=".WRITE_EXTERNAL_STORAGE"></uses-permission>
 <uses-feature android:name="" />
 <uses-feature android:name="" />
 <uses-permission android:name="" />

minSdkVersion 16  //Configuration 16implementation'.yuzhiqiang1993:zxing:2.2.1' //rely

external

allprojects {
 repositories {
  google()
  jcenter()
  maven { url '' } //Add this line of code }
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.