Exciting things

Play SWF in Android application

Our client asks for an Android native application that loads their SWF files (for presentation purpose) and allow the end user to play with them. 

I did the code quickly for testing this. At the beginning, I missed some points. So, I face to some small issues: the Flash cannot be loaded. It takes me some mins to do the Google around.

Below is the code, very simple:

public class EmbedWebViewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        WebView webView = (WebView) findViewById(R.id.webView);
        webView.getSettings().setPluginsEnabled(true); //require setting
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setAllowFileAccess(true);
        
        webView.loadUrl("file:///android_asset/load_swf.html");
        
    }
}

I put the webView.getSettings().setJavaScriptEnabled(true) line because we have some needs to run some special Javascript besides of playing with the Flash file. Hope it helps to save you some mins like me 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *