繁体   English   中英

在Android设备上找不到“网页未找到”“file:///android_asset/html-nl/index.html not found”错误

[英]“Webpage not found” “file:///android_asset/html-nl/index.html not found” error on android device

我的Android应用程序正在使用phonegap 2.7和barcodescanner插件。 当我使用模拟器测试它时,一切正常。

但是,当我在我的设备上测试它时,第一次点击“扫描”它会重定向到一个页面说:

“网页不可用:无法加载网页文件:///android_asset/html-nl/index.html”。

(我翻译了这个,所以使用英文设备的错误可能略有不同)

当我点击继续时,该应用程序继续正常工作。 奇怪的是,这只在我第一次安装应用程序时发生。 当我第二次点击“扫描”时,一切正常。

(我的代码的一部分):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(在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>

在main.js中,有scanCode()函数:

var scanCode = function() {
window.plugins.barcodeScanner.scan(
        scanSuccess,
        function(error) {
            alert("Scan failed: " + error);
        });
};

额外信息:我母语的缩写是“nl”...它可能与它无关,但我想我让你们知道......

提前致谢!

编辑:它可能与语言有关...这个主题描述了完全相同的问题......: http//www.anddev.org/other-coding-problems-f5/problem-with-scanner-in -motorola-XT320-t2178445.html

然而没有解决方案:(

编辑:用我的语言设置为英语进行测试。 实际上,它显示:无法加载文件:///android_asset/html-en/index.html的网页。 我发现问题在于扫描仪。 每次安装后它第一次被解雇,它都会重定向到那个页面...... ZXing可能正试图达到这个目的: https//github.com/zxing/zxing/blob/master/android/assets/html-en /index.html 不知道为什么,没有改变任何东西到源代码。

解决方案:我发现当安装新版本的应用程序时,ZXing会自动加载HelpActivity。 在该活动中,重定向到html-userlanguage。 易于修复:只需告诉脚本(它在com.google.zxing.client.android中)不要加载HelpActivity。

问题是在将应用程序安装到设备时,android / assets文件夹未打包在.apk文件中。 我正在使用Android Studio,所以这就是我在build.gradle文件中的内容:

android {compileSdkVersion 16 buildToolsVersion“17.0.0”

defaultConfig {
    minSdkVersion 13
    targetSdkVersion 16
}

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }
}

}

无需修改HelpActivity.java。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM