Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 gradle/android_project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.8.2'
classpath 'com.android.tools.build:gradle:8.11.0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Gluon
* Copyright (c) 2016, 2025, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -54,29 +54,7 @@
* when used.</p>
*
* <p><b>Android Configuration</b></p>
* <p>The permission <code>android.permission.CAMERA</code> needs to be added together
* with the following <code>activity</code> configuration that handles the SCAN intent
* of the BarcodeScanService.</p>
*
* <pre>
* {@code <manifest ...>
* <uses-permission android:name="android.permission.CAMERA"/>
* ...
* <application ...>
* ...
* <activity android:name="com.gluonhq.helloandroid.zxing.CaptureActivity"
* android:screenOrientation="sensorLandscape"
* android:clearTaskOnLaunch="true"
* android:stateNotNeeded="true"
* android:windowSoftInputMode="stateAlwaysHidden">
* <intent-filter>
* <action android:name="com.gluonhq.attach.barcodescan.android.SCAN"/>
* <category android:name="android.intent.category.DEFAULT"/>
* </intent-filter>
* </activity>
* <activity android:name="com.gluonhq.impl.attach.plugins.android.PermissionRequestActivity" />
* </application>
* </manifest>}</pre>
* <p>None</p>
*
* <p><b>iOS Configuration</b></p>
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Gluon
* Copyright (c) 2016, 2025, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,27 +36,6 @@

import java.util.Optional;

/**
* Requires this permission: android.permission.CAMERA
*
* And this activity added to the AndroidManifest.xml:
*
* <pre>
* {@code
* <activity android:name="com.gluonhq.helloandroid.zxing.CaptureActivity"
* android:screenOrientation="sensorLandscape"
* android:clearTaskOnLaunch="true"
* android:stateNotNeeded="true"
* android:windowSoftInputMode="stateAlwaysHidden">
* <intent-filter>
* <action android:name="com.gluonhq.attach.barcodescan.android.SCAN"/>
* <category android:name="android.intent.category.DEFAULT"/>
* </intent-filter>
* </activity>
* <activity android:name="com.gluonhq.helloandroid.PermissionRequestActivity" />
* }
* </pre>
*/
public class AndroidBarcodeScanService implements BarcodeScanService {

static {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Gluon
* Copyright (c) 2020, 2025, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -29,70 +29,57 @@

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import com.gluonhq.helloandroid.zxing.Intents.Scan;
import com.google.mlkit.common.MlKitException;
import com.google.mlkit.vision.barcode.common.Barcode;
import com.google.mlkit.vision.codescanner.GmsBarcodeScanner;
import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions;
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning;

public class DalvikBarcodeScanService {

private static final String TAG = Util.TAG;
private static final int SCAN_CODE = 10002;
public static final String SCAN_VIEW_TITLE = "ScanViewTitle";
public static final String SCAN_VIEW_LEGEND = "ScanViewLegend";
public static final String SCAN_VIEW_RESULT = "ScanViewResult";

private final Activity activity;
private final Intent scanIntent;

public DalvikBarcodeScanService(Activity activity) {
this.activity = activity;
scanIntent = new Intent(Scan.ACTION);
scanIntent.addCategory(Intent.CATEGORY_DEFAULT);
scanIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
scanIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
}

private void scan(String title, String legend, String resultText) {
if (title != null && !title.isEmpty()) {
scanIntent.putExtra(SCAN_VIEW_TITLE, title);
}

if (legend != null && !legend.isEmpty()) {
scanIntent.putExtra(SCAN_VIEW_LEGEND, legend);
}

if (resultText != null && !resultText.isEmpty()) {
scanIntent.putExtra(SCAN_VIEW_RESULT, resultText);
}

if (!Util.verifyPermissions(Manifest.permission.CAMERA)) {
Log.e(TAG, "Camera is disabled");
return;
}
GmsBarcodeScannerOptions options = new GmsBarcodeScannerOptions.Builder()
.enableAutoZoom()
.build();

IntentHandler intentHandler = new IntentHandler() {
@Override
public void gotActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == SCAN_CODE && resultCode == Activity.RESULT_OK) {
String result = (String) intent.getExtras().get("SCAN_RESULT");
// a barcode was scanned
GmsBarcodeScanner scanner = GmsBarcodeScanning.getClient(activity, options);
scanner.startScan()
.addOnSuccessListener(barcode -> {
if (Util.isDebug()) {
Log.v(TAG, "Current barcodescan result: " + result);
Log.v(TAG, "Barcodescan succeeded with result: " + barcode.getRawValue() + " and format " + barcode.getFormat());
}
nativeBarcodeScanResult(result);
}
}
};
nativeBarcodeScanResult(barcode.getRawValue());
})
.addOnCanceledListener(() -> {
if (Util.isDebug()) {
Log.v(TAG, "Barcodescan was cancelled");
}
})
.addOnFailureListener(e -> Log.e(TAG, "Barcodescan failed with error: " + getErrorMessage(e)));
}

if (activity == null) {
Log.e(TAG, "Activity not found. This service is not allowed when "
+ "running in background mode or from wearable");
return;
private String getErrorMessage(Exception e) {
if (e instanceof MlKitException) {
switch (((MlKitException) e).getErrorCode()) {
case MlKitException.CODE_SCANNER_CAMERA_PERMISSION_NOT_GRANTED:
return "Camera permission not granted";
case MlKitException.CODE_SCANNER_APP_NAME_UNAVAILABLE:
return "app name unavailable";
default:
return e.getMessage();
}
} else {
return e.getMessage();
}

Util.setOnActivityResultHandler(intentHandler);

activity.startActivityForResult(scanIntent, SCAN_CODE);
}

private native void nativeBarcodeScanResult(String result);
Expand Down

This file was deleted.

This file was deleted.

Loading