Issue
I'm new to android development and I'm trying to figure out how to load an HTML file that I have which contains a video. Everytime I run my app on my mobile it crashes.
This is my code which is found in the onCreate main class.
WebView wv = (WebView)this.findViewById(R.id.video);
WebSettings wbset=wv.getSettings();
wbset.setJavaScriptEnabled(true);
wv.setWebViewClient(new WebClientClass());
wv.loadUrl("file:///assets/video.html");
I have the video in the assets folder. This is my manifest xml class.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.video"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And the activity is right here.
<pre lang="text">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_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="com.example.video.MainActivity" >
<WebView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
Solution
Use#
wv.loadUrl("file:///android_asset/video.html");
Instead#
wv.loadUrl("file:///assets/video.html");
For further detail refer Printing HTML Documents.
Answered By - RobinHood
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.