WebView加载swf

WebView加载swf

直接上代码:

源程序:

package com.vinvo.android.demos.swftest;

 

import java.lang.reflect.InvocationTargetException;

import java.lang.reflect.Method;

 

import android.app.Activity;

import android.os.Bundle;

import android.util.Log;

import android.webkit.WebView;

import android.webkit.WebViewClient;

import android.widget.FrameLayout;

 

public class SwfTestActivity extends Activity {

private WebView mWebView;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

        mWebView = (WebView)findViewById(R.id.webview);

        mWebView.getSettings().setJavaScriptEnabled(true);

        mWebView.getSettings().setPluginsEnabled(true);

        mWebView.setWebViewClient(new WebViewClient() {

            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                view.loadUrl(url);

                return true;

            }

        });

        

        mWebView.loadUrl("file:///android_asset/index.htm");

    }

    

    /**

     * 调用隐藏的WebView方法 <br />

     * 说明:WebView完全退出swf的方法,停止声音的播放。

     * @param name

     */

    private void callHiddenWebViewMethod(String name){

    if (mWebView != null){

    try{

    Method method = WebView.class.getMethod(name);

    method.invoke(mWebView); // 调用

    } catch (NoSuchMethodException e) { // 没有这样的方法

    Log.i("No such method: " + name, e.toString());

    } catch (IllegalAccessException e) { // 非法访问

    Log.i("Illegal Access: " + name, e.toString());

    } catch (InvocationTargetException e) { // 调用的目标异常

    Log.d("Invocation Target Exception: " + name, e.toString());

    }

    }

}

 

    @Override

    protected void onPause(){

    super.onPause();

    mWebView.pauseTimers();

 

    if (isFinishing()){

    mWebView.loadUrl("about:blank");

    setContentView(new FrameLayout(this));

    }

    callHiddenWebViewMethod("onPause");

}

 

    @Override

    protected void onResume(){

    super.onResume();

    mWebView.resumeTimers();

    callHiddenWebViewMethod("onResume");

}

}

AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

      package="com.vinvo.android.demos.swftest"

      android:versionCode="1"

      android:versionName="1.0"

      android:installLocation="auto">

    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

 

    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <activity android:name=".SwfTestActivity"

                  android:label="@string/app_name"

                  android:screenOrientation="landscape"

                  android:configChanges="orientation|keyboardHidden"

                  android:theme="@style/Theme.FaceScreen">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

 

    </application>

</manifest>

 

布局main.xml文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent" 

    android:layout_height="fill_parent"

    android:background="#200000">

 

    <WebView android:id="@+id/webview" 

        android:layout_height="fill_parent" 

        android:layout_width="fill_parent"

        android:scrollbars="none"

        android:background="#200000"/>

</LinearLayout>

 

index.htm文件:

<html>

<head>

    <meta charset="utf-8" />

    <title>swf</title>

    <style>

        *{ margin:0; padding:0; background:#000000;}

    </style>

</head>

<body>

    <div>

        <center>

            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

                id="swf" width="75%" height="100%"

                codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">

                <param name="movie" value="banded.swf" />

                <param name="quality" value="high" />

                <param name="bgcolor" value="#000000" />

                <embed src="banded.swf" algin="middle" quality="high" bgcolor="#000000" width="75%" height="100%" align="middle" play="true" loop="false" quality="high"> </embed>

            </object>

        </center>

    </div>

</body>

</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值