0

Данное приложение считывает QR код и выводит результат, как сделать сканер в "портретном" режиме? Если можно конкретный код, который поможет

MainActivity

  public class MainActivity extends AppCompatActivity {
        private Button button, button1;
        private TextView txtResult;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            button = (Button) this.findViewById(R.id.button);
            txtResult = (TextView)findViewById(R.id.txtResult);
            final Activity activity = this;
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick (View v){
                    IntentIntegrator integrator = new IntentIntegrator(activity);
                    integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
                    integrator.setPrompt("Сканирование");
                    integrator.setCameraId(0);
                    integrator.setBeepEnabled(false);
                    integrator.setBarcodeImageEnabled(false);
                    integrator.initiateScan();
                    integrator.setOrientationLocked(true);
                }
            });
        }
        @SuppressLint("SetTextI18n")
        @Override
        protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
            IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
            if(result !=null){
                if(result.getContents() == null){
                    Log.d("MainActivity", "Cancelled scan");
                    Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
                } else{
                    Log.d("MainActivity", "Scanned");
                    txtResult.setText("Результат сканирования: " + "\n" + result.getContents());
                   // Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
                }
            } else {
                super.onActivityResult(requestCode,resultCode,data);
            }
        }
    }

AndroidManifest

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="GoogleAppIndexingWarning">
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:configChanges="orientation|keyboardHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

6

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.