Loading

Thursday, October 20, 2011

Load local HTML webpage inside APK

Using WebView, your app can load local HTML file (inside your APK).

Load local HTML webpage inside APK

Create your own HTML file under /assets/ folder.

/assets/mypage.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width; user-scalable=0;" />
<title>My HTML</title>
</head>
<body>
<h1>MyHTML</h1>
</body>
</html>


Modify main.xml to add a WebView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<WebView
android:id="@+id/mybrowser"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>


Java code
package com.exercise.AndroidHTML;

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

public class AndroidHTMLActivity extends Activity {

WebView myBrowser;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myBrowser = (WebView)findViewById(R.id.mybrowser);

myBrowser.loadUrl("file:///android_asset/mypage.html");

}
}


Download the files.

Related article:
- AndroidBrowser, implement a Android Browser using WebView
- Run Android Java code from Webpage



SHARE TWEET

Thank you for reading this article Load local HTML webpage inside APK With URL http://x-tutorials.blogspot.com/2011/10/load-local-html-webpage-inside-apk.html. Also a time to read the other articles.

0 comments:

Write your comment for this article Load local HTML webpage inside APK above!