开发者

how to run html dynamic pages on android

开发者 https://www.devze.com 2023-03-17 09:22 出处:网络
Hello guys I am facing one issue while running interlinked html pages on android amulator. Its just showing index page but links are not working.

Hello guys I am facing one issue while running interlinked html pages on android amulator. Its just showing index page but links are not working.

package neeru.test;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class TestActivity extends Activity {
    /** Called when the activit开发者_如何学JAVAy is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         WebView webview = new WebView(this);
         setContentView(webview);
         try {
             InputStream fin = getAssets().open("index.html");
             byte[] buffer = new byte[fin.available()];
             fin.read(buffer);
             fin.close();
             webview.loadData(new String(buffer), "text/html", "UTF-8");
             } catch (IOException e) {
                 e.printStackTrace();
                 }
         }
     } 


use something like this:

private final static String URL = "file:///android_asset/index.html";
...
mWebView.loadUrl(URL);

then it should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号