How to play .swf files in Android?

2019-09-16 00:09发布

问题:

I installed Adobe Flash Player apk by copying it from assets to SD card and installing it using Intent. Even after that, webView is not able to load the .swf file.

Should i use Adobe Flash builder instead to develop the Android application. My primary requirement is to play .swf files from the server!

Here is my code.

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

        installFlashPlayer();


//Fake Url
//        String url = "http://www.test.com/test.swf";
//
//        webView = (WebView) findViewById(R.id.webView);
//        webView.getSettings().setPluginState(WebSettings.PluginState.ON);
//        webView.setWebViewClient(new WebViewClient());
//
//        webView.getSettings().setUseWideViewPort(true);
//        webView.getSettings().setLoadWithOverviewMode(true);
//        webView.loadUrl(url);

    }

    void installFlashPlayer(){
        AssetManager assetManager = FlashActivity.this.getAssets();

        InputStream in = null;
        OutputStream out = null;

        try {
            in = assetManager.open("flp.apk");
            out = new FileOutputStream(Environment.getExternalStorageDirectory()  + "/flp.apk");

            byte[] buffer = new byte[1024];

            int read;
            while((read = in.read(buffer)) != -1) {

                out.write(buffer, 0, read);

            }

            in.close();
            in = null;

            out.flush();
            out.close();
            out = null;

            Intent intent = new Intent(Intent.ACTION_VIEW);

            intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/flp.apk")),
                    "application/vnd.android.package-archive");

            startActivity(intent);

        } catch(Exception e) { }
    }

回答1:

You can use "GeckoView of Firefox" I used this in my project.

Useful for playing swf files.

Also you need to set plugin.state.flash = true; in GeckoView..

The bad idea is your apk will increase 20-25 mb if you choose to use GeckoView (if i didnot remember wrong) , because GeckoView works with jni...