如何将html文件加载到Android应用程序? [英] How to load html file to android app?

查看:104
本文介绍了如何将html文件加载到Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android开发的新手,我正在试图找出如何加载包含视频的HTML文件。每次我在我的手机上运行我的应用程序时都会崩溃。



这是我的代码,可以在onCreate主类中找到。



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");





我有视频输入资产文件夹。这是我的清单xml类。





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>

</manifest>





活动就在这里。





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>





不确定导致应用崩溃的原因。任何帮助将非常感激! :)



Not really sure what is causing the app to crash. Any help would be really appreciated! :)

推荐答案

**使用#**



wv.loadUrl(" file:/ //android_asset/video.html");



**相反#**



wv。 loadUrl(" file:///assets/video.html");



详情请参阅:



developer.android.com/training/printing/html-docs.html
**Use#**

wv.loadUrl("file:///android_asset/video.html");

**Instead#**

wv.loadUrl("file:///assets/video.html");

For further detail refer :

developer.android.com/training/printing/html-docs.html


找出问题所在。我需要打开一个新的意图并启用java。
Figured out the problem. I needed to open a new intent and enable java.


这篇关于如何将html文件加载到Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆