0

I want to play flash file (SWF) in in android but I can't I use this code to show it in WebView but it not work for me.

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 
mWebView.setBackgroundColor(Color.parseColor("#00FF00"));
mWebView.loadUrl("file:///android_asset/game.swf");
Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45

1 Answers1

0

First create a HTML file to load the swf:

game.html

<html>
      <head>
        <meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
  </head>
  <body>
    <object width="215" height="140">
      <param name="game" value="game.swf">
        <embed src="file:///android_asset/game.swf"
               width="215" height="140">
        </embed>
    </object>
  </body>
</html>

Then for the android part:

package webView.video;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.webkit.WebView;


public class WebViewActivity extends Activity {
private WebView mWebView;

/** Called when the activity is first created. */
     @Override
     public void onCreate (Bundle savedInstanceState) {
         super. onCreate (savedInstanceState);
         setContentView(R.layout.main);



         // html file with sample swf video in sdcard

         //swf2.html points to swf in sdcard

         mWebView = (WebView)findViewById(R.id.webview);
         mWebView.getSettings().setJavaScriptEnabled(true);
         mWebView.getSettings().setPluginsEnabled(true);
         mWebView.getSettings().setAllowFileAccess(true); 
         mWebView.loadUrl("yourHtmlfile.html");

     }
}

Saw it in this question How to Play local swf files in a webview credits goes to him...

Community
  • 1
  • 1
Eefret
  • 4,724
  • 4
  • 30
  • 46
  • it says "Couldn't load plug-in" and i install flash player on the phone but still it not work. – user3715342 Apr 29 '15 at 21:15
  • which version of android are u running ? I think after 4.1 its unlikely to work any flash in webview, I found it out in this post http://stackoverflow.com/questions/22293310/using-webview-and-adobe-flash-player-plugin-to-play-swf-flash-doesnt-work-in-a – Eefret Apr 30 '15 at 14:22
  • so what should i do for playing SWF in android? – user3715342 Apr 30 '15 at 14:55
  • I dont think it will be possible right know at least until they update the android Webview to support it again. – Eefret Apr 30 '15 at 18:32