Credntia / MVBarcodeReader

A Barcode scanner library for Android. Uses the Google Play Services' mobile vision api for barcode detection.
Apache License 2.0
68 stars 22 forks source link

Fragment problem #10

Closed AugustoAleGon closed 7 years ago

AugustoAleGon commented 7 years ago

Hello Mehedi,

I already took the id and put it in the right place, but it is the same problem. It gives me an error of E/Zygote: MountEmulatedStorage(). After 3 times trying It gives an error of camera. This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/barScannerFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF"
    tools:context="com.example.android.barscanner.ScanLandscapeActivity">

    <fragment
        android:name="devliving.online.mvbarcodereader.BarcodeCaptureFragment"
        android:layout_width="200dp"
        android:layout_height="800dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true" />
</RelativeLayout>

I am using this activity:

package com.example.android.barscanner;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.google.android.gms.vision.barcode.Barcode;

import java.util.List;

import devliving.online.mvbarcodereader.BarcodeCaptureFragment;
import devliving.online.mvbarcodereader.MVBarcodeScanner;

public class ScanLandscapeActivity extends AppCompatActivity implements BarcodeCaptureFragment.BarcodeScanningListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan_landscape);
        MVBarcodeScanner.ScanningMode mode = null;
        mode = MVBarcodeScanner.ScanningMode.SINGLE_MANUAL;
        @MVBarcodeScanner.BarCodeFormat int[] formats = null;

        BarcodeCaptureFragment fragment = BarcodeCaptureFragment.instantiate(mode, formats);
        getSupportFragmentManager().beginTransaction()
                .add(R.id.barScannerFragment, fragment)
                .commit();
    }

    @Override
    public void onBarcodeScanned(Barcode barcode) {

    }

    @Override
    public void onBarcodesScanned(List<Barcode> barcodes) {

    }

    @Override
    public void onBarcodeScanningFailed(String reason) {

    }
}

and this is my main activity:

package com.example.android.barscanner;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void scanActivity(View view){
        Button scanButton = (Button) findViewById(R.id.buttonScanner);
        Intent scanBarIntent = new Intent(this, ScanLandscapeActivity.class);
        startActivity(scanBarIntent);
    }
}

I still have an error. I already checked if I have the permission on the camera in the manifest. It pops up the camera and then it crashes. @iamMehedi

iamMehedi commented 7 years ago

This is not a library related issue. You don't need to add the fragment programmatically if you have already added in layout xml. If you want to add it in code then just have an empty FrameLayout in your xml where you would like the scanner to be and add the fragment in that framelayout from code. Reading the docs and tutorials on using fragments should help.

AugustoAleGon commented 7 years ago

ohh I see @iamMehedi Thanks for your support I will check that information relative to fragments. I am still have to practice a lot. Thanks again for taking your time to answer my question.