playing .swf on application startup

徘徊边缘 提交于 2019-12-11 05:47:38

问题


I want that i play .swf file when the android user clicks on the application icon and the application starts and after that i want to start the application's activity. Here is what i thought and what i have done until now.

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);


    }   
}

Here is my xml file:

<?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> 

Is there anything wrong with it?? seems like the code is not working! secondly setPluginsEnabled(true); is also not being picked up by eclipse!


回答1:


startActivity(yes_krao) is called immediately after you have loaded the WebView so the application will switch Activities before your .swf has a chance to play. One solution would be to implement a Handler and switch Activities after the duration of your .swf file.

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);
    }   
}

Note that setPluginsEnabled() has been deprecated, so you should use setPluginState():

WebSettings webSettings = yourWebView.getSettings();
webSettings.setPluginState(PluginState.ON);


来源:https://stackoverflow.com/questions/18997257/playing-swf-on-application-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!