19

I'm having problems with this. If I go to an SWF directly in the browser, it works fine. If I attempt to use loadUrl on an SWF file it stays blank and loads nothing.

Joren
  • 8,851
  • 17
  • 60
  • 97

3 Answers3

20

Figured it out. You have to enable plugins.

webview.getSettings().setPluginsEnabled(true);
Joren
  • 8,851
  • 17
  • 60
  • 97
  • "method has been deprecated since API level 9, and was removed in API level 18", note frmo my answer below. – Darpan Jul 05 '16 at 13:36
4

Niky, you have a code example here.

I have used this example to test this code and confirm it works. In this example the qualibus.swf is in contained within the assets of the app. Please test this on an actual device, as on the emulator it show a blank page (probably the flash player is not present on the emulator)

Test3Activity.java:

package com.blabla.test3;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

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

        String url ="file:///android_asset/qualibus.swf";

        WebView wv=(WebView) findViewById(R.id.webView1);
        wv.getSettings().setPluginsEnabled(true);
        wv.loadUrl(url);
    }
}

main.xml:

<?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/webView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent">
</WebView>
</LinearLayout>

Result:

Application running and displaying swf in web view

Community
  • 1
  • 1
ZoltanF
  • 286
  • 1
  • 7
  • sorry i am have applied the same procedure but http://stackoverflow.com/questions/9308712/how-to-run-the-swf-file-in-android-emulator got this error – VENKI Feb 16 '12 at 11:11
  • 4
    i can not find wv.getSettings().setPluginsEnabled(true); method... i can only find webView.getSettings().setPluginState(PluginState.ON); method... please help me – Pradip Bhatt Sep 14 '13 at 05:47
2

The function WebView.getSettings().setPluginsEnabled(); method has been deprecated since API level 9, and was removed in API level 18.

You can use the newer function WebView.getSettings().setPluginState(WebSettings.PluginState.ON);
which was added in API level 8 and was deprecated in API level 18.

According to the WebSettings Documentation API levels beyond 18 will not support plugins; I'm assuming it's because the main plugin to support was flash which adobe is no longer developing for mobile.

Quoted from source

So, for now you can use it till 18, and handle compatibility with higher APIs (sadly)

Community
  • 1
  • 1
Darpan
  • 5,193
  • 3
  • 45
  • 74