WEBVIEW loadFile() 的几个BUG以及修复

UIWebViewImpl-android.cpp:

//Modified by Liu Yi
std::string getUrlStringByFileName(const std::string &fileName) {
LOGE(“error: %s,%d”,func,LINE);
const std::string basePath(“file:///android_asset/”);

int pos=(int) fileName.find("?");
std::string params="";

std::string realName;

if(pos>0){
     realName=fileName.substr(0,pos);
    params=fileName.substr(pos);
}else{
    realName=fileName;

}

std::string fullPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(realName);
const std::string assetsPath("assets/");

std::string urlString;
if (fullPath.find(assetsPath) != std::string::npos) {
    urlString = fullPath.replace(fullPath.find_first_of(assetsPath), assetsPath.length(), basePath);
} else {
    urlString = fullPath;
}



 urlString=urlString+params;

return urlString;

}

有时候loadfile 安卓获取到的是没有file://的

修改:Cocos2dxWebViewHelper.java

public static void loadFile(final int index, final String filePath) {
Log.e(“play2learn”,“filePath>>”+filePath);

    if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) {
        CocosPlayClient.updateAssets(filePath);
    }
    CocosPlayClient.notifyFileLoaded(filePath);
    sCocos2dxActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Cocos2dxWebView webView = webViews.get(index);
            if (webView != null) {
             
             
             String path=filePath;

if(path.indexOf(“file://”)!=0){

              path="file://"+path;

             }
              Log.e("play2learn","filePath:"+filePath);
                webView.loadUrl(path);
            }
        }
    });
}