My android app is using phonegap 2.7 and the barcodescanner plugin. When I test it using an emulator, everything works fine.
However, when I test it on my device, the first time I hit "Scan" it redirects to a page saying:
"Webpage not available: the webpage file:///android_asset/html-nl/index.html cannot be loaded".
(I translated this so the error could be slightly different using an English device)
When I hit Continue, the app continues to work properly. The weird thing is, this only happens the first time I install the app. When I hit "Scan" a second time, everything works fine.
(a part of) my code: AppActivity.Java
package com.myapp.app;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
public class AppActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
index.html (in assets/www):
<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
<script type="text/javascript" src="barcodescanner.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<h1>Testing!</h1>
<a href="#" onclick="scanCode();">Scan Code</a>
</body>
</html>
In main.js, there's the scanCode() function:
var scanCode = function() {
window.plugins.barcodeScanner.scan(
scanSuccess,
function(error) {
alert("Scan failed: " + error);
});
};
Extra info: my mother language's abbreviation is "nl"... it probably has nothing to do with it, but I'd figure I let you guys know...
Thanks in advance!
EDIT: it probably HAS something to do with the language... this topic describes the exact same problem...: http://www.anddev.org/other-coding-problems-f5/problem-with-scanner-in-motorola-xt320-t2178445.html
No solution however :(
EDIT: tested it with my language set to English. Indeed, it shows: The Web page at file:///android_asset/html-en/index.html could not be loaded. I found that the problem lies with the scanner. Everytime it's fired for the first time after install, it redirect to that page... ZXing is probably trying to reach this one: https://github.com/zxing/zxing/blob/master/android/assets/html-en/index.html . Don't know why, didn't change anything to the source code.
Solution: I found that ZXing auto-loads HelpActivity when a new version of the app is installed. In that activity, there's the redirect to html-userlanguage. Easy to fix: just tell the script (it's in com.google.zxing.client.android) not to load the HelpActivity.