Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Fix/analyze null pointer exception #279

Open
wants to merge 2 commits into
base: ml-kit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<!-- <uses-permission android:name="android.permission.VIBRATE" /> -->

<uses-permission android:name="android.permission.VIBRATE" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -299,70 +299,72 @@ public void analyze(@NonNull ImageProxy image) {
@SuppressLint("UnsafeOptInUsageError")
Image mediaImage = image.getImage();

if (mediaImage != null) {
InputImage inputImage = InputImage.fromMediaImage(mediaImage, image.getImageInfo().getRotationDegrees());

Task<List<Barcode>> result = mScanner
.process(inputImage)
.addOnSuccessListener(
new OnSuccessListener<List<Barcode>>() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onSuccess(List<Barcode> barcodes) {
if (scanningPaused) {
return;
}
for (Barcode barcode : barcodes) {
PluginCall call = getSavedCall();
if (mediaImage == null || mScanner == null) {
return;
}

Rect bounds = barcode.getBoundingBox();
Point[] corners = barcode.getCornerPoints();
String rawValue = barcode.getRawValue();
InputImage inputImage = InputImage.fromMediaImage(mediaImage, image.getImageInfo().getRotationDegrees());

Task<List<Barcode>> result = mScanner
.process(inputImage)
.addOnSuccessListener(
new OnSuccessListener<List<Barcode>>() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onSuccess(List<Barcode> barcodes) {
if (scanningPaused) {
return;
}
for (Barcode barcode : barcodes) {
PluginCall call = getSavedCall();

// add vibration logic here
Rect bounds = barcode.getBoundingBox();
Point[] corners = barcode.getCornerPoints();
String rawValue = barcode.getRawValue();

String s = bounds.flattenToString();
Log.e(MLKIT_TAG, "content : " + rawValue);
// Log.e(MLKIT_TAG,"corners : " + corners.toString());
Log.e(MLKIT_TAG, "bounds : " + bounds.flattenToString());
// add vibration logic here

Log.e(MLKIT_TAG, "Added Into ArrayList : " + rawValue);
String s = bounds.flattenToString();
Log.e(MLKIT_TAG, "content : " + rawValue);
// Log.e(MLKIT_TAG,"corners : " + corners.toString());
Log.e(MLKIT_TAG, "bounds : " + bounds.flattenToString());

JSObject jsObject = new JSObject();
int[] boundArr = { bounds.top, bounds.bottom, bounds.right, bounds.left };
Log.e(MLKIT_TAG, "onSuccess: boundArr");
jsObject.put("hasContent", true);
jsObject.put("content", rawValue);
jsObject.put("format", null);
// jsObject.put("corners",corners);
jsObject.put("bounds", s);
Log.e(MLKIT_TAG, "Added Into ArrayList : " + rawValue);

if (call != null && !call.isKeptAlive()) {
destroy();
}
call.resolve(jsObject);
JSObject jsObject = new JSObject();
int[] boundArr = { bounds.top, bounds.bottom, bounds.right, bounds.left };
Log.e(MLKIT_TAG, "onSuccess: boundArr");
jsObject.put("hasContent", true);
jsObject.put("content", rawValue);
jsObject.put("format", null);
// jsObject.put("corners",corners);
jsObject.put("bounds", s);

if (call != null && !call.isKeptAlive()) {
destroy();
}
call.resolve(jsObject);
}
}
)
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(MLKIT_TAG, e.toString());
}
}
)
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(MLKIT_TAG, e.toString());
}
)
.addOnCompleteListener(
new OnCompleteListener<List<Barcode>>() {
@Override
public void onComplete(@NonNull Task<List<Barcode>> task) {
image.close();
mediaImage.close();
}
}
)
.addOnCompleteListener(
new OnCompleteListener<List<Barcode>>() {
@Override
public void onComplete(@NonNull Task<List<Barcode>> task) {
image.close();
mediaImage.close();
}
);
}
}
);
}

@PluginMethod
Expand Down