Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.7k views
in Technique[技术] by (71.8m points)

android - Is there any way to load swf file into andoird

I am loading SWF file into Andriod.

I am trying with webview, but there is an error couldn't load plug-in

String text="<html>
" +
        "  <head>
" +
        "    <meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
" +
        "  </head>
" +
        "  <body>
" +
        "<h1>jvjhvjhv</h1>
"+
        "    <object width="215" height="140">
" +
        "      <param name="movie" value="airplane.swf">
" +
        "        <embed src="file:///android_asset/airplane.swf"
" +
        "               width="215" height="140">
" +
        "        </embed>
" +
        "    </object>
" +
        "  </body>
" +
        "</html>";
private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (WebView)findViewById(R.id.web);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
    mWebView.getSettings().setAllowFileAccess(true);
    //mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.getSettings().setUserAgentString("Mozilla/5.0 (Mobile; Android; rv:48.0) Gecko/48.0 Firefox/48.0 KAIOS/2.0");

    mWebView.loadData(text,"text/html","utf-8");
}

Can anyone give me an answer to load SWF file in android?

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"I am loading SWF file into Android.
I am trying with WebView, but there is an error saying "Could not load plug-in".
Can anyone give me an answer to load SWF file in Android?"

You could try: SWF 2 JS. You want to save this file swf2js.js and use in your own HTML code.
Success will depend on your SWF file content. SWF2JS supports Flash animations and AS2 code.

  • I've not tested this in an Android WebView (with dynamic HTML string) but on PC it expects files to be accessed from either online or else via device's localhost server.

  • If any problems loading an animation. Try using files from location: https:// not file:///.

Demos (test if these can display on your Android device) :

1) Flash graphics: https://vcone.github.io/public/flash/demo1.html

2) Game with code: https://vcone.github.io/public/flash/demo2.html

If the above SWF files work on Android, then you can try some embed code like below:

<head>
<script type="text/javascript" src="file:///android_asset/swf2js.js"></script>
</head>

<body>

ADROID TEST: Displaying SWF with JavaScript and HTML5 Canvas... <br><br>

<div id="myFlashDiv" style="width:800px; height:800px;"></div>

<script type="text/javascript">

var mySWF = swf2js;
mySWF.load('file:///android_asset/airplane.swf', {"tagId": "myFlashDiv"});

</script>

</body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...