yuriy-budiyev / code-scanner Goto Github PK
View Code? Open in Web Editor NEWCode scanner library for Android, based on ZXing
License: MIT License
Code scanner library for Android, based on ZXing
License: MIT License
Thx for the library, is there any way to fix this issue ?
Example: https://ww2.justanswer.com/uploads/ASEMaster35yrs/2011-05-29_221358_doortag.jpg
I am working with devices having android version 8 and 5.1. It works as expected with version 8 device but with device having version 5.1 , it runs very slowly. The scanning time for that device is more than 1.5 minutes. User have to wait for long time than expected. I would like to request you to suggest me to improve this problem.
I am using this library with a dialog and the preview and its internal representation SurfaceView mPreviewView; has bad Layoutparams. new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT
As a consequence the preview surface view is outside of the bound of my dialog. Is there a way to fix it?
can i use this library for barcode ?
hay @yuriy-budiyev your library was so good works well with back camera.But it isn't works well with front cam.
In Android kitkat 4.4.4 when using front cam i got through a toast "failed to connect to camera services", I used the same in Android 5.0 and above, its working.
I preferred your library mainly bcuz focus option for front cam but in my case the focus button is also disabled during front cam with 5.0 and above.
Is it depends on the hardware?
The camera quality is really bad, I will look check the code myself but I'm not comparing to the original camera application quality, it doesn't even compare with the Zxing camera intent demo, it's usable on my Pixel 2 XL but not with my other test phones. Please let me know if we can do something regarding this.
Hi! Nice work. But sometimes when opening and closing several times, the activity scanner takes a long time to open and in the log it shows the error: Camera: Error 100 and it opens after a few seconds. And sometimes when you want to close the activity scanner it stays frozen for a few seconds and the activity is closed. Thanks.
XML:
<com.budiyev.android.codescanner.CodeScannerView android:id="@+id/scanner_view" android:layout_width="match_parent" android:layout_height="match_parent" app:frameColor="@color/scanner_frame_color" app:autoFocusButtonVisible="false" app:flashButtonVisible="false" app:frameThickness="4dp" app:frameCornersRadius="2dp" />
Kotlin:
`import android.os.Bundle
import android.view.View.VISIBLE
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.budiyev.android.codescanner.CodeScanner
import com.budiyev.android.codescanner.DecodeCallback
import com.budiyev.android.codescanner.ErrorCallback
import com.cloudsourceit.pnletouroperador.R
import com.google.zxing.BarcodeFormat
import kotlinx.android.synthetic.main.activity_scanner.*
class ScannerActivity : AppCompatActivity() {
private lateinit var scanner: CodeScanner
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_scanner)
setSupportActionBar(toolbar)
// We use our own toolbar title, so hide the default one
supportActionBar?.setDisplayShowTitleEnabled(false)
toolbar.setNavigationOnClickListener {
finish()
}
scanner = CodeScanner(this, scanner_view).apply {
this.formats = listOf(BarcodeFormat.QR_CODE)
this.decodeCallback = DecodeCallback {
image_success.visibility = VISIBLE
Toast.makeText(this@ScannerActivity, "Scan result: ${it.text}", Toast.LENGTH_LONG).show()
}
this.errorCallback = ErrorCallback {
Toast.makeText(this@ScannerActivity, "Camera initialization error: ${it.message}",
Toast.LENGTH_LONG).show()
}
}
}
override fun onResume() {
super.onResume()
scanner.startPreview()
}
override fun onPause() {
scanner.releaseResources()
super.onPause()
}
}`
Hello!
My Code:
BarcodeUtils.encodeBitmap(code, BarcodeFormat.EAN_13, 400, 150)
exception:
Process: ru.packa.pivovaroff, PID: 14959
java.lang.ArrayIndexOutOfBoundsException: length=1950; index=1953
What am I doing wrong?
Using Android SDK v.24
W/CameraBase: An error occurred while connecting to camera 0: Service not available
W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
E/AndroidRuntime: FATAL EXCEPTION: cs-init
Process: com.fuib.bridgest, PID: 19022
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.(Camera.java:556)
at android.hardware.Camera.open(Camera.java:372)
at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:764)
at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:741)
Code:
public class LoginActivity extends AppCompatActivity {
private CodeScanner mCodeScanner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
CodeScannerView scannerView = findViewById(R.id.scanner_view);
mCodeScanner = new CodeScanner(this, scannerView);
mCodeScanner.setCamera(CodeScanner.CAMERA_BACK);
mCodeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull final Result result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), result.getText(), Toast.LENGTH_SHORT).show();
}
});
}
});
scannerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCodeScanner.startPreview();
}
});
}
@Override
protected void onResume() {
super.onResume();
mCodeScanner.startPreview();
}
@Override
protected void onPause() {
mCodeScanner.releaseResources();
super.onPause();
}
}
When U Added implementation 'com.budiyev.android:code-scanner:2.0.0', I get the above error in the issue title.
This is my configuration:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ticket.ticketingsystem"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.budiyev.android:code-scanner:2.0.0'
}
hello i have this message
class anonymous derived from decodecallback must be either declarated abstract or implemnt abstract method on decoded
the override line before ondecoded say method does not override from it superclass
The issue I have seen on the Pixel 2 XL and I believe the Pixel 2 as well is that for some reason if the QR Code is an exact fit in the view finder frame, it does not scan. I have to move the phone back a bit a relatively considerable amount (QR Code smaller in camera ~8-10 inches) and then it scans properly.
And in my testing (testing various devices, Samsung, LG, Pixel 1, Pixel 2) the Pixel 2/XL are the only phones to have this issue.
Why is this a problem?
Users will habitually try to fit the QR Code in the frame and not think to move it back because its counter intuitive
Proposed Solution
Add option to the code scanner to pass in the full width rect instead of the rect of the viewfinder (currently fixed at 0.75 of width and with my PR that is adjustable) to the decoder task so that it scans a larger area than the view finder and is able to scan the QR Code on devices that may have this issue
Obviously this would be an option with perhaps the following api
codeScanner.setScanFrameOverride(true|false)
codeScanner.setScanFrameSize(0.1 <= frameSize <= 1.0)
or even
codeScanner.setFullWidthScan(true|false) which would tell the codeScanner to use the full width frame of the viewfinderview instead of frameRect(which it is doing right now)
How can we add a moving scanning line as in the following image:
Hi! I would like touch preview screen and try to make focus on place touched.
Could you add this feature?
Thanks for the lib. It works fine!
Hello,
thank you for this library. I am just wondering, if there is any way how can I speed up the recognition of QR code. I want to scan just QR codes and right after show different screen based on the scanned data (ScanMode.SINGLE). But the recognition takes quite long time. Although the conditions are good. There are no other codes in the camera view, good light conditions etc. It takes more then 15 seconds and I need to move the camera to by able to scan the code.
This is my code:
scannerView = mViews!!.scannerView
mCodeScanner = CodeScanner(activity, scannerView!!)
mCodeScanner?.let {
mCodeScanner.setDecodeCallback(this)
mCodeScanner.setErrorCallback(this)
mCodeScanner.isAutoFocusEnabled = true
mCodeScanner.setAutoFocusInterval(1000)
mCodeScanner.setFormats(BarcodeFormat.QR_CODE)
mCodeScanner.setScanMode(ScanMode.SINGLE)
}
I am using the 1.7.5 version. Thank you for any suggestions.
Current Behavior
Focus by touch stop working
Expected Behavior
Focus by touch should always work
Step to reproduce bug
1.Touch the screen to start focus
2. Touch the screen before focus finish
3. Touch the screen to perform focus again but nothing happened
Setting used
AutoFocusEnabled(false);
TouchFocusEnabled(true);
First off thank you for the library
My problem is the Qr code reading take quite a while to read anything up to 30 seconds is there a fix for this using version 2.0.1
Hi @yuriy-budiyev ,
thank you for this library.
I'm using it in my app but I have an issue. When device is rotated in portrait mode only the first scan of a barcode takes about 20 seconds to decode. If I rotate device to landscape and then again in portrait, or if I start my app in landscape mode barcode decoding is immediate.
Plz Consider
Great work, but can you provide a changelog so that it is easier to keep track of changes?
Thanks!
In logcat: W/CameraBase: An error occurred while connecting to camera: 0
mCodeScanner.setCamera(findCamera());
mCodeScanner.startPreview();
private int findCamera() {
int numberOfCameras = Camera.getNumberOfCameras();
int cameraId = 0;
for (int i = 0; i < numberOfCameras; i++) {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
cameraId = i;
break;
}
}
return cameraId;
}
Hi,
Does this library need minSDK is 19? Can it run on lower sdk? My app supports minSDK 17, then cannot integrate with your lib due to this error.
Hi,
Is it possible to add feature to recognize 1D barcode (EAN) when code is placed vertically?
The application is made to be portrait only, but I need to be able to scan codes in all orientations without moving the device.
Here is the screenshot from my app where you can see what do I need.
Thank you for your help.
Hey! Very nice component, thank you!
Is it possible to manage zoom of camera?
Its possible to change the icons?
Android Studio cannot import class import com.google.zxing.Result but at the same time the code is compiled normally.
Tried to do a clean up project - did not help.
If you know what the problem is, then please help me a lot.
i can't run it in Android Studio, it says no module
Hi, great lib!
I want to know for what is the icon in the top-left corner in QR scanner view, i click on it but nothing happens.
Regards
If CodeScannerView is not full screen, all child items are shifted down by parent top offset value. For example, if CodeScannerView is centered vertically or has Top margin.
Workaround is to insert CodeScannerView into dummy LinearLayout, to make top offset 0.
Hey Yuriy and fellow developers, i would want to ask how to change the scanner orientation using whether the ScannerView
or CodeScanner
class. Or rather can you help me to make the scanner be orientation independent (scan in both orientation states). so far it seems to be portrait fixed when scanning PDF417, QR Code is working in all orientation
Cheers
Hi, we have implemented your library without any trouble, but we are facing one issue. Front camera is too dark and can't read codes. We have tested camera by opening default device camera application and ti is much brighter and more clear than the screen we are getting through library in our app. Can you help us in resolving this? Thanks.
Currently, the default max is 0.75 of the screen. I think it would be nice to have this be customizable just like the other settings.
I have made the changes and will create a PR for this
Hi @yuriy-budiyev and thanks for the library!
I have an issue with a low FPS (~20) when I am scanning barcodes on my Pixel 2 (and some other devices). On some devices FPS is pretty good but on some devices - no.
I am wondering could it be fixed or it's by design?
Why FOCUS_MODE_CONTINUOUS_PICTURE or FOCUS_MODE_CONTINUOUS_VIDEO auto focus mode is not used? I think it will give more consistent result comparing to current auto focus implementation. Currently camera constantly resets focus and this looks really weird.
Hi
A nice and "easy-to-implement" project. Just an issue that I came across on my Samsung S4 mini (KitKat). When using the front camera the preview is upside-down.
Thanks
On a Huawei test device with Android 6.0(M) the activity with the code scanner view just consistently crashes with this unknown camera error. Is there anything that we can do?
Unknown camera error(-1)
java.lang.RuntimeException: Unknown camera error(-1)
at android.hardware.Camera.(Camera.java:593)
at android.hardware.Camera.open(Camera.java:414)
at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:736)
at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:713)
Hi, general request:
I needed some specification for my app, and couldn't do any changes/inheritance/access to fields
all classes are final or final & private(or accessible in the same package only)
fields are private (not protected) without getters
it's impossible to have small change without cloning the repository
please make it more accessible
thanks
How to vibrate as the user scanned the code?
app take much time to recognize the barcode pattern
Hi Thanks for providing library. I need scanner frame rounded. Can you provide a solution how to set radius to frame.
Program type already present: com.google.zxing.client.android.camera.CameraConfigurationUtils
Message{kind=ERROR, text=Program type already present: com.google.zxing.client.android.camera.CameraConfigurationUtils, sources=[Unknown source file], tool name=Optional.of(D8)}
Using Java Activity, not sure if it will automatically detect the QR on sight like iOS, or I have to manually tap the screen. Either ways it is not hitting any response or error breakpoints.
Project building is failed with error :
More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'
Please help with it.
I'm having trouble in scanning the QR codes. I'm attaching a high sample image of QR code making trouble.
its working file with other scanners which have used same Xing Library but don't know why giving issue on this one. I have also tried to enabled all formats by mCodeScanner.setFormats(CodeScanner.ALL_FORMATS);
but still issue remain same. Can you please specify the solution ASAP.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.