Load an SWF into a WebView
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.
Figured it out. You have to enable plugins.
webview.getSettings().setPluginsEnabled(true);
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:
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)
精彩评论