加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

WebView加载swf

发布时间:2020-12-15 18:08:41 所属栏目:百科 来源:网络整理
导读: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.ut

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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读