Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

journeyapp's barcodeview showing black view only

I have setup a barcode scanner using JourneyApp's BarCode Scanner Library

I have added dependencies just like in the read-me of the library.

Then, I set up a BarCode View in my main activity like this

main_activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  tools:context=".MainActivity">

  <com.journeyapps.barcodescanner.BarcodeView
    android:id="@+id/barcode_scanner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  </com.journeyapps.barcodescanner.BarcodeView>

</RelativeLayout>

I leave the MainActivity.java as default. This is it's OnCreate Method

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

I have added Camera Permission in my manifest too.

When I run the app on the phone. The BarCodeView shows only a black screen. Am I doing anything wrong here?

Black Screen

like image 924
Vincent Paing Avatar asked Jul 25 '15 15:07

Vincent Paing


1 Answers

Take a look at the sample code inside journeyapp's repository here.

You have to resume and pause the barcode view inside onResume() and onPause() respectively.

So, inside onCreate() message you have to get a handler for the BarcodeView view:

BarcodeView barcodeView = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.continuous_scan); 
   barcodeView = (DecoratedBarcodeView) findViewById(R.id.barcode_scanner);               
}

And also you have to add both onResume() and onPause() methods:

@Override
protected void onResume() {
    super.onResume();
    barcodeView.resume();
}

@Override
protected void onPause() {
    super.onPause();
    barcodeView.pause();
}
like image 163
Rafael Adel Avatar answered Oct 26 '22 23:10

Rafael Adel