package com.example.cosmosclient.views; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.TextView; import com.example.cosmosclient.R; import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; import com.journeyapps.barcodescanner.CaptureActivity; public class QRcodeReadingActivity extends CaptureActivity { public String QRcodeData = null; TextView QRcodeResult; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_qrcode_reading); QRcodeResult = findViewById(R.id.QRcodeResult); //ここでQRコードリーダーオブジェクト生成 IntentIntegrator integrator = new IntentIntegrator(this); // new IntentIntegrator(QRcodeReadingActivity.this).initiateScan(); // スキャン画面の回転の制御 integrator.setOrientationLocked(false); //バーコードリーダーの起動 integrator.initiateScan(); } //QRコードから読み取った結果の取得 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if(result != null) { QRcodeData = (String)result.getContents(); QRcodeResult.setText(QRcodeData); } else { super.onActivityResult(requestCode, resultCode, data); } } }