Problem loading swf file in android
I have a problem when I load interactive SWF file in android emulator. I use 2.3.1 AVD.
This is the code:
package com.androidpeople.view;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.androidpeople.com");
webView.setWebViewClient(new HelloWebViewClient());*/
String html =
"<object width=\"550\" height=\"400\"> <param name=\"movie\" value=\"file:///android_asset/FL.swf\"> <embed src=\"file:///android_asset/FL.swf\" width=\"550\" height=\"400\"> </embed> </object>";
String mimeType = "text/html";
String encoding = "utf-8";
WebView wv=(WebView) findViewById(R.id.webview);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginsEnabled(true);
wv.loadDataWithBaseURL("null", html, mimeType, encoding, "");
wv.setWebViewClient(new HelloWebViewClient());
}
}
package com.androidpeople.view;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidpeople.view"
android:versionCode="1"
android:version开发者_如何学PythonName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".WebViewExample"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="5" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Now the problem is that when I run the project, it will give one box at center right side 3D dimension like:
I have also tried to change different-different SWF file but can't get proper solution.
Can anyone help me? Thanks.
Replace
wv.loadDataWithBaseURL("null", html, mimeType, encoding, "");
with
wv.loadData(html, mimeType, encoding, "");
wv.getSettings().setJavaScriptEnabled(true);
That's just because you need to install flash Player. Download the apk from adobe website and install it on the emulator.
Flash cannot run on the emulator!
At least, I did not find a way to do so. But, you can download an APK from this site and install it on your device. Then, using the following code I got flash to work.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.loadUrl("http://www.adobe.com/software/flash/about/");
}
In activity_main.xml:
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
精彩评论