扫描时自动更改屏幕方向(使用ZXING库) [英] Change screen orientation automatically while scanning (using ZXING library)

查看:217
本文介绍了扫描时自动更改屏幕方向(使用ZXING库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有MainActivity.kt,其中显示了满足不同需求的不同片段.有时,我按下按钮"X"调用startScanner()函数:

I've MainActivity.kt where I show different fragments for different needs. At some point, I press button 'X' that calls startScanner() function:

private fun startScanner() {
    IntentIntegrator(this)
            .setOrientationLocked(false)
            .setPrompt("SCANNING?")
            .initiateScan()
}

Manifest.xml:

<activity
    android:name=".MainActiity"
    android:theme="@style/AppTheme"
    tools:replace="android:screenOrientation"
    android:stateNotNeeded="true"
    android:screenOrientation="fullSensor"
    android:windowSoftInputMode="stateHidden" />

Gradle.file:

compile 'com.journeyapps:zxing-android-embedded:3.6.0'

它确实会打开扫描仪以及所有内容,但是处于横向模式.

It does open scanner and everything, but in landscape mode.

为什么这不起作用?

推荐答案

有一个执行此操作的快捷方式.只需将其添加到清单中即可:

There is a shortcut to do this. Just add this to the manifest:

<activity
       android:name="com.journeyapps.barcodescanner.CaptureActivity"
       android:screenOrientation="portrait"
       tools:replace="android:screenOrientation"
       android:stateNotNeeded="true"/>

这篇关于扫描时自动更改屏幕方向(使用ZXING库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆