Tripapp travel barcode shows only black view
I have installed a barcode scanner using JourneyApp BarCode Scanner Library
I added dependencies as in the read-me library.
Then I set BarCode View in my main activity like
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 am leaving MainActivity.java as default. This is the OnCreate method
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
I also added the camera permission to my manifest.
When I run the app on my phone. BarCodeView only displays black screen. Am I doing something wrong here?
source to share
I know it has been 6 months since the question was asked, but maybe someone else can handle this issue. (I really hope you found a solution).
Your layout is completely correct, you are just missing the initialization code for the barcodeView.
In your activity onResume add method:
protected void onResume () {
BarcodeView v = (BarcodeView)findViewById(R.id.barcode_view);
v.resume();
v.decodeSingle(new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
// Do whatever you want with the result
}
@Override
public void possibleResultPionts(List<ResultPoint> resultPoints) {
}
});
}
Hope this helps!
source to share
Take a look at the sample code inside the tripapp repository here .
You should resume
both pause
see the barcode inside onResume()
and onPause()
accordingly.
So, inside the post, onCreate()
you need to get a handler for the view BarcodeView
:
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 need to add methods onResume()
and onPause()
:
@Override
protected void onResume() {
super.onResume();
barcodeView.resume();
}
@Override
protected void onPause() {
super.onPause();
barcodeView.pause();
}
source to share
You need to add the following permission to AndroidManifesl.xml
From Android version 6, you need to ask for permission at runtime. Executes the documentation for requesting permission at runtime. https://developer.android.com/training/permissions/requesting.html?hl=en
source to share