Android 14 Camera Permission
August 7, 2025 · AI Conversations
{
var TOKEN = 'circusvegastoken';
$(document).ready(function()
{
var eventId = -1;
var eventDateId = -1;
var scanConfig = {
preferFrontCamera : false, // iOS and Android
showFlipCameraButton : true, // iOS and Android
showTorchButton : true, // iOS and Android
torchOn: false, // Android, launch with the torch switched on (if available)
saveHistory: false, // Android, save scan history (default false)
prompt : "Place a code inside the scan area", // Android
resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
formats : "QR_CODE", // default: all but PDF_417 and RSS_EXPANDED
//orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
disableAnimations : true, // iOS
disableSuccessBeep: false // iOS and Android
};
var sendCode = function(code)
{
$('.scan').prop('disabled', true);
$('.manually').prop('disabled', true);
$('#scan-result').removeClass('bg-success').addClass('bg-dark').html('Code '+ code +' sent to boxoffice, plase wait…');
$.ajax({
url: 'https://boxoffice.circusvegasonwheels.com/index.php/api/scan',
method: 'POST',
data: {
token: TOKEN,
event_date_id: eventDateId,
order_code: code
},
success: function(result,status,xhr)
{
var apiResult = JSON.parse(result);
if ( apiResult.result )
{
$('#scan-result').removeClass('bg-dark').addClass('bg-success').html(apiResult.message+''+apiResult.seating+''+apiResult.tickets);
// reset input to set next code
$('[name="code"]').val(eventId +'.'+ eventDateId +'.');
}
else
{
$('#scan-result').removeClass('bg-success').addClass('bg-dark').html(apiResult.message);
}
},
error: function(xhr,status,error)
{
$('#scan-result').removeClass('bg-success').addClass('bg-dark').html('Code '+ result.text +' could not be sent to boxoffice, please try again');
},
complete: function()
{
$('.scan').prop('disabled', false);
$('.manually').prop('disabled', false);
}
});
}
var scanError = function (error)
{
$('#scan-result').removeClass('bg-success').addClass('bg-dark').html("Scanning failed: " + error);
$('#modal-scan-result').modal('show');
};
var scanSuccess = function(result)
{
if (! result.cancelled )
{
if (eventDateId > -1)
{
sendCode(result.text);
}
else
{
$('#scan-result').removeClass('bg-success').addClass('bg-dark').html('You must select an event date to scan tickets');
}
}
else
{
$('#scan-result').removeClass('bg-success').addClass('bg-dark').html('Scan was cancelled');
}
$('#modal-scan-result').modal('show');
};
$(document).on('click', '.reload-events', function()
{
$('ul.events').html('');
$.ajax({
url: 'https://boxoffice.circusvegasonwheels.com/index.php/api/today',
method: 'POST',
data: {
token: TOKEN
},
success: function(result,status,xhr)
{
var events = JSON.parse(result);
$.each(events, function(i, val)
{
var eventDatetime = new Date(val.event_datetime);
var dateOptions = { year: '2-digit', month: '2-digit', day: '2-digit' };
var timeOptions = { hour12: true, hour: '2-digit', minute: '2-digit' };
$('.events').append(''+eventDatetime.toLocaleDateString('en-GB', dateOptions)+' – '+ eventDatetime.toLocaleTimeString('en-US', timeOptions) +' Wednesday – '+ val.venue_full +'');
});
},
error: function(xhr,status,error)
{
console.log(error);
}
});
});
// load events click
$('.reload-events').trigger('click');
$(document).on('click', '.events .list-group-item', function()
{
$('.events .list-group-item').removeClass('active');
$(this).addClass('active');
$('#scan-info').html($(this).html());
eventId = $(this).attr('data-event-id');
eventDateId = $(this).attr('data-event-date-id');
$('[name="code"]').val(eventId +'.'+ eventDateId +'.');
// first scan on event date click
//cordova.plugins.barcodeScanner.scan(scanSuccess, scanError, scanConfig);
$('#modal-scan-result').modal('show');
});
$(document).on('click', '.scan', function()
{
cordova.plugins.barcodeScanner.scan(scanSuccess, scanError, scanConfig);
});
$(document).on('click', '.manually', function()
{
sendCode($('[name="code"]').val());
});
});
}, false);
Not working in android 14
cordova.plugins.barcodeScanner
If the scanner isn't working in Android 14, it's likely due to **missing permissions or incorrect plugin usage**.
—
### ✅ Here's how to fix it:
—
### 1. **Ensure Camera Permission in `AndroidManifest.xml`**
In `platforms/android/app/src/main/AndroidManifest.xml`, confirm this is added **inside “:**
<uses-permission android:name="android.permission.CAMERA" />
—
### 2. **Request Runtime Permission in JavaScript**
Android 6+ requires runtime permission. Add this before calling `barcodeScanner.scan`:
document.addEventListener('deviceready', function () {
cordova.plugins.diagnostic.requestCameraAuthorization(function(status) {
console.log("Camera permission status is: " + status);
}, function(error){
console.error("The following error occurred: "+error);
}, true); // true for runtime permissions on Android
}, false);
Install the `cordova.plugins.diagnostic` plugin if not already installed:
cordova plugin add cordova.plugins.diagnostic
—
### 3. **Use the Latest Version of BarcodeScanner Plugin**
Some older versions are **not compatible with Android 13+**. Make sure you are using:
cordova plugin rm phonegap-plugin-barcodescanner
cordova plugin add phonegap-plugin-barcodescanner@latest
—
### 4. **Target SDK Fix for Android 14**
Check your `config.xml` or `build.gradle` and make sure you're targeting at least API 33 (for Android 13+), and fully compatible with 34:
<preference name="android-targetSdkVersion" value="34" />
—
### 5. **Troubleshooting**
If scanning still fails:
– Test on a real device (not emulator)
– Use `adb logcat` to check errors:
adb logcat | grep barcode
– Make sure your app has camera access in Android settings (`App Info > Permissions`)
—
### ✅ Sample Safe Trigger
Wrap your scan call like this:
cordova.plugins.diagnostic.isCameraAuthorized(function(authorized) {
if (authorized) {
cordova.plugins.barcodeScanner.scan(scanSuccess, scanError, scanConfig);
} else {
cordova.plugins.diagnostic.requestCameraAuthorization(function(status) {
if (status === cordova.plugins.diagnostic.permissionStatus.GRANTED) {
cordova.plugins.barcodeScanner.scan(scanSuccess, scanError, scanConfig);
} else {
alert("Camera permission is required to scan codes.");
}
}, null, true);
}
}, function(error){
console.error("Error checking camera authorization: " + error);
});
—
Let me know if you want a version that **auto-prompts** and retries the scan after permission is granted.
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
———–
* Where:
Script '/home/admin1/nethues-projects/Klassenergy-project/android-apps/circusscanner/platforms/android/phonegap-plugin-barcodescanner/scanner-barcodescanner.gradle' line: 9
* What went wrong:
A problem occurred evaluating script.
> Could not find method compile() for arguments [{name=barcodescanner-release-2.1.5, ext=aar}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
—
### ❌ Error Summary:
Could not find method compile() for arguments [{name=barcodescanner-release-2.1.5, ext=aar}]
—
### ✅ Fix:
You need to **replace `compile()` with `implementation()`** in the plugin's Gradle file.
—
### 🔧 Steps to Fix:
1. Open the file causing the error:
/platforms/android/phonegap-plugin-barcodescanner/scanner-barcodescanner.gradle
2. Go to **line 9** or wherever you see:
compile(name: 'barcodescanner-release-2.1.5', ext: 'aar')
3. **Change it to:**
implementation(name: 'barcodescanner-release-2.1.5', ext: 'aar')
—
### 📌 But Wait — This File Gets Rewritten on Plugin Install!
To fix this **permanently**, you have **2 options**:
—
#### 🔁 Option 1: Patch the Plugin Manually
– Go to:
plugins/phonegap-plugin-barcodescanner/src/android/
– Edit or override `scanner-barcodescanner.gradle` to use `implementation` instead of `compile`.
– Rebuild with:
cordova clean android
cordova build android
—
#### 📦 Option 2: Use a Maintained Fork or Patch
Unfortunately, the `phonegap-plugin-barcodescanner` is no longer well maintained.
Use this fork which supports Android 13+ and Gradle 7+:
cordova plugin remove phonegap-plugin-barcodescanner
cordova plugin add https://github.com/TimNN/phonegap-plugin-barcodescanner.git
This fork already uses `implementation` internally.
—
### ✅ After Fixing
1. Clean the project:
cordova clean
2. Rebuild:
cordova build android
—
Let me know if you want me to generate a fixed version of the `scanner-barcodescanner.gradle` file or help you migrate to a better-maintained plugin.