Closed vofili closed 6 years ago
Hey @vofili
Can you show me the code you used. You don't need to use it as navigator.scan. You can directly use scan.
You can try this in console after just adding the plugin and running the cordova app on an android device then going into google chrome and type in chrome://inspect/#devices
into the search bar then press enter. Here you will see your app under which there will be an inspect button you can click. On click a new window opens with a console. Try typing in scan and it should autofill if everything is working correctly.
@ChrisTomAlx - I am also facing same issue, scan scan is not defined
i have already added plugin. But it's only in Android in iOS it's working very well..
yeah sure
@ChrisTomAlx - Here you can see...
scan.scanDoc(0, function(imageURI) { console.log(imageURI); });
@Karanveer-logiciel && @vofili What android version are you using. Is it Android Oreo? If so please use the fix that has been provided in the readme file under issues and fixes.
By the way, @Karanveer-logiciel , I tried your code and my code, both are working fine. Are you using the function before the device ready event? If that is the case it won't work. If you could create a new test app with this plugin and your code and you send it to me. I will test on my end and see what might be the problem.
Hi @ChrisTomAlx
Here is my code
document.addEventListener("deviceready", onScanDeviceReady, false);
function onScanDeviceReady() {
Scan.scanDoc(sourceType, successCallback, errorCallback);
}
function successCallback(imageData){
console.log("picture taken - ",imageData);
localStorage.setItem("chequefrontpicture",imageData);
var image = document.getElementById('imagechequefrontpicture');
image.src = "data:image/jpeg;base64," + imageData;
}
function errorCallback(error){
localStorage.setItem("imagedata","");
console.log("error picture taken - ",error);
}
i have used this line
scan.scanDoc(sourceType, successCallback, errorCallback);
and this line
Scan.scanDoc(sourceType, successCallback, errorCallback);
both returned
scan is undefined
@ChrisTomAlx - I tried both ways as you told but not working for me and i am using after device ready also...
Hey @vofili ,
Okay three things I noticed
To be more clear. Use scan
.
Scan
won't work.
Also change sourcetype to either 0 or 1.
Use the function after the deviceready event was received. For eg it would look like below in your index.js :-
var app = {
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
onDeviceReady: function() {
this.receivedEvent('deviceready');
//device ready received
scan.scanDoc(0, onSuccess, onFail);
function onSuccess(imageURI) {
console.log(imageURI);
}
function onFail(message) {
alert('Failed because: ' + message);
}
},
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
app.initialize();
Hey @Karanveer-logiciel
Unfortunately, I will need more information to help you. The best thing you can do is create a new app with the plugin and your code. Make sure it isn't working in yours then send it over to me and I will test if it is working on my end. If it is we can find our way out from there./
@ChrisTomAlx - FYI i am using CORDOVA CLI -> 6.5.0
@ChrisTomAlx - Can you help me to find this plugin in platform folder may it will be helpfull for me
Im using Cordova v7.1.0 and android v 7.1.0
okay @ChrisTomAlx
I upgraded my platform android
ionic cordova platform add android@7.1.0
and now i can use the scan object.
I am also able to call scanDoc
Thank you.. You're a legend..
@Karanveer-logiciel
You can find the java files of the plugin here :- platforms\android\app\src\main\java\com\neutrinos\plugin
and the js files here :- \platforms\android\app\src\main\assets\www\js
I am closing this issue for now, since it seems upgrading to cordova version 7.1.0+ should solve this issue for you as well. Sorry I couldn't be of more help.
Hi, I'm having the same problem. "Uncaught ReferenceError: Scan is not defined" I'm using cordova and cordova android platform 11.0.0
I integrated the plugin on cordova and cannot find the scan object. I keep getting undefined undefined", source: file:///android_asset/www/index.html (37) [INFO:CONSOLE(38)] "window plugins scan", source: file:///android_asset/www/index.html (38) [INFO:CONSOLE(39)] "undefined", source: file:///android_asset/www/index.html (39) [INFO:CONSOLE(40)] "window Scan", source: file:///android_asset/www/index.html (40) [INFO:CONSOLE(41)] "undefined", source: file:///android_asset/www/index.html (41) [INFO:CONSOLE(42)] "navigator.scan", source: file:///android_asset/www/index.html (42