0

fromフォルダにロードしようとしてoffline version of python documentationいます。オフライン ドキュメントは、私の PC Web ブラウザーではオフラインで完全に機能しますが、適切に機能しません( .webviewassetwebviewjquery is missing

@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webView = (WebView) findViewById(R.id.wrapper);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadUrl("file:///android_asset/python/index.html");
    }

}

また、ホームページを読み込もうとしたり、任意のページに移動しようとすると、このエラー メッセージが表示されます。

09-24 01:03:02.789: E/Web Console(479): ReferenceError: Can't find variable: $ at file:///android_asset/python/index.html:164

そして、上記のエラーは Jquery コード スニペットに対するものです (これは、jquery ライブラリが読み込まれていないためだと思います)

<script type="text/javascript">$('#searchbox').show(0);</script>

しかし、ローカル サーバーlocalhostまたはhttpサーバーからこれらのページを読み込むと、これは完全に機能します。私は何を取りこぼしたか?

編集 に何も表示されませんwebView。使用後loadDataWithBaseURL

@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webView = (WebView) findViewById(R.id.wrapper);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient());
        AssetManager assetManager = getAssets();
        String htmlPage = null;
        InputStream input;
        try {
            input = assetManager.open("python/index.html");

            int size = input.available();
            byte[] buffer = new byte[size];
            input.read(buffer);
            input.close();
            // byte buffer into a string
            htmlPage = new String(buffer);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
            webView.loadDataWithBaseURL("file:///android_asset/", htmlPage, "text/html", "utf-8", "");

    }
}
4

2 に答える 2

0

問題は、これらの Web ファイルを phonegap アプリのアセット フォルダーから抽出したことです。それらには、いくつかの追加ファイルと異なる構造がありました。Androidナイーブ環境で動かなかったのはそのためです!

于 2014-08-16T03:37:49.347 に答える