convert a html to android Application using android webview
This is MainActivity.java file:
package bd.edu.httpdaffodilvarsity.htmlconvert;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String myURL = "file:///android_asset/www/index.html";
WebView webView_KSera_Convert_HTML_to_Android =(WebView)findViewById(R.id.webViewKSeraConvertHTMLtoAndroid);
webView_KSera_Convert_HTML_to_Android.getSettings().setJavaScriptEnabled(true);
webView_KSera_Convert_HTML_to_Android.setWebViewClient(new WebViewClient());
webView_KSera_Convert_HTML_to_Android.loadUrl(myURL);
}
}
This is activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="bd.edu.httpdaffodilvarsity.htmlconvert.MainActivity">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webViewKSeraConvertHTMLtoAndroid"/>
</RelativeLayout>
AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bd.edu.httpdaffodilvarsity.htmlconvert">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
index.html file:
<!Doctype html>
<html>
<head>head</head>
<body>
<h1>Hello World</h1>
<h4>Hello</h4>
</body>
</html>
build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "bd.edu.httpdaffodilvarsity.htmlconvert"
minSdkVersion 10
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
}
Error in Emulator:
Folder structure: