1

我希望在 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捡起来!

4

1 回答 1

1

startActivity(yes_krao)在您加载后立即调用,WebView因此应用程序将在您的 .swf 有机会播放之前切换活动。一种解决方案是在 .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);

        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);
于 2013-09-25T06:25:25.873 回答