在应用程序启动时播放.swf

时间:2013-09-25 05:56:08

标签: android flash splash-screen

我希望当Android用户点击应用程序图标并启动应用程序时播放.swf文件,之后我想启动应用程序的活动。以下是我的想法以及到目前为止所做的事情。

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebView;
import android.webkit.WebSettings.PluginState;

public class Splash_Screen extends Activity {

     private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.startup);

        new Handler().postDelayed(new Runnable() {

            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                String localUrl ="file:///android_asset/Kiss-o-meter.swf";

                WebView wv=(WebView) findViewById(R.id.webview);
                wv.getSettings().setPluginState(PluginState.ON);
                wv.loadUrl(localUrl);       

                Intent yes_krao = new Intent(Splash_Screen.this, KissingMeter.class);
                startActivity(yes_krao);
                finish();
            }
        }, SPLASH_TIME_OUT);


    }   
}

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"> 

     <WebView android:id="@+id/webview" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"/>

</LinearLayout> 

它有什么问题吗?好像代码不起作用!其次 setPluginsEnabled(true); 也没有被eclipse选中!

1 个答案:

答案 0 :(得分:1)

加载startActivity(yes_krao)后立即调用

WebView,以便应用程序在您的.swf有机会玩之前切换活动。一种解决方案是在.swf文件的持续时间之后实现Handler并切换活动。

E.g:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebView;
import android.webkit.WebSettings.PluginState;

public class Splash_Screen extends Activity {

     private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.startup);

        String localUrl ="file:///android_asset/Kiss-o-meter.swf";

        WebView wv=(WebView) findViewById(R.id.webview);
        wv.getSettings().setPluginState(PluginState.ON);
        wv.loadUrl(localUrl); 

        new Handler().postDelayed(new Runnable() {

            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity      
                Intent yes_krao = new Intent(Splash_Screen.this, KissingMeter.class);
                startActivity(yes_krao);
                finish();
            }
        }, SPLASH_TIME_OUT);
    }   
}

请注意, setPluginsEnabled()已弃用,因此您应使用 setPluginState()

WebSettings webSettings = yourWebView.getSettings();
webSettings.setPluginState(PluginState.ON);
相关问题