2
1

More than 3 years have passed since last update.

ZXingのバーコード読み取り画面を縦方向にしたい

Last updated at Posted at 2019-12-09

ZXingを使用する際にデフォルトだと横方向になってしまうのを縦方向に表示するようにした自分メモです。

結論

CaptureActivity を継承した、空の Activity 作成し、 IntentIntegrator の captureActivity に渡してあげる。

// 空の Activity を作成
private class PortraitActivity : CaptureActivity()
// 自分の場合は Fragment 内で使用していたので、forSupportFragment(this) としてあげています。
val integrator = IntentIntegrator.forSupportFragment(this).apply {
            setPrompt("QRを読み込んでください")
            captureActivity = PortraitActivity::class.java // ここで渡してあげる
        }
integrator.initiateScan()

とりあえず、これだけ行えばバーコードリーダーを開いた際に縦画面になります。

最後に

今は ZXing は initateScan() ですぐに読み取りが行えるのですが、情報が英語の方が多い気がしています。。
今後はドキュメントの豊富な Firebase の方に移行するかもです。
移行した時はまた記事を書きたいと思います。
見ていただきありがとうございます。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1