1. 程式人生 > >android載入.swf flash檔案

android載入.swf flash檔案

專案結構:


一、SwfTest.java

package com.example.helloworld;


import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;


public class MainActivity extends Activity {

private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//隱藏標題,設定全屏:必須在新增顯示內容之前,否則報錯
requestWindowFeature(Window.FEATURE_NO_TITLE);  //隱藏標題
/*getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); *///設定全屏
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.web);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);  //JS可用
//webSettings.setPluginsEnabled(true);//過時
webSettings.setPluginState(WebSettings.PluginState.ON);//設定adobe外掛可用
//mWebView.loadUrl("http://dashan.vip5.flashyc.net/swf/tpbfq3.swf");//網路資源
mWebView.loadUrl("file:///android_asset/02.swf");
}

}

二、flash檔案要放在assets資料夾下

三、activity_main.xml

<FrameLayout 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:orientation="horizontal"
    tools:context=".MainActivity" >

    <WebView
        android:id="@+id/web"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/black" />

</FrameLayout>

四、AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloworld"
    android:versionCode="1"
    android:versionName="1.0" >


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


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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.helloworld.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="unspecified" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

android:screenOrientation="unspecified"時:如下圖是豎向的,至於細節部分大家還是根據自己的需求自己改吧



android:screenOrientation="landscape"時:如下圖是橫屏


注:執行時手機上要安裝Flash Player 外掛