bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

怎么在Android中實現掃描和生成二維碼-創新互聯

這篇文章主要介紹了怎么在Android中實現掃描和生成二維碼的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇怎么在Android中實現掃描和生成二維碼文章都會有所收獲,下面我們一起來看看吧。

創新互聯公司長期為近1000家客戶提供的網站建設服務,團隊從業經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯網生態環境。為平果企業提供專業的網站設計、成都網站制作,平果網站改版等技術服務。擁有十多年豐富建站經驗和眾多成功案例,為您定制開發。

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() { //點擊按鈕掃描二維碼
   @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!=null){
    String content = data.getStringExtra(Constant.CODED_CONTENT);
    if (TextUtils.isEmpty(content)){

     Toast.makeText(MainActivity.this, "您的輸入為空!", 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,"掃描"+content,Toast.LENGTH_SHORT).show();


   }
  }
 }
}

activity.main.xml

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity"
 android:orientation="vertical">

 <Button
  android:id="@+id/btn"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="掃一掃"/>

 <ImageView
  android:id="@+id/img"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  />

</android.support.constraint.ConstraintLayout>

需要配置的權限

<uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.CAMERA"></uses-permission>
 <uses-permission android:name="android.permission.VIBRATE" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />
 <uses-permission android:name="android.permission.FLASHLIGHT" />

build.gradle

minSdkVersion 16  //配置16
implementation'com.github.yuzhiqiang1993:zxing:2.2.1' //依賴

外部build.gradle

allprojects {
 repositories {
  google()
  jcenter()
  maven { url 'https://jitpack.io' } //加這行代碼
 }
}

關于“怎么在Android中實現掃描和生成二維碼”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“怎么在Android中實現掃描和生成二維碼”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注創新互聯行業資訊頻道。

標題名稱:怎么在Android中實現掃描和生成二維碼-創新互聯
分享網址:http://vcdvsql.cn/article46/ceoghg.html

成都網站建設公司_創新互聯,為您提供小程序開發定制網站網站改版靜態網站網頁設計公司ChatGPT

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

網站建設網站維護公司