1

I am developing an application for android 3.0 tablet, that's supposed to play swf files inside a WebView. First I tried to open the swf file from the device, than through the internet, with no luck. The WebView shows up, but inside the WebView all I can see is a black screen (with a 3-4 px wide white line on the right). If I load the same URL to the device browser, the flash file plays well. I think Im missing something on the WebView setup, but after a few hours of searching and googling I still dont know what.

The Java code:

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setContentView(R.layout.presentation);

    presentationWebView = (WebView) findViewById(R.id.presentation_webview);

    presentationWebView.getSettings().setJavaScriptEnabled(true);
    presentationWebView.getSettings().setPluginsEnabled(true);
    presentationWebView.getSettings().setAllowFileAccess(true);
    presentationWebView.loadUrl("http://my_domain/fileName.swf");

}

The presentation.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <WebView
        android:id = "@+id/presentation_webview"
        android:layout_width = "fill_parent"
        android:layout_height = "fill_parent"/>
</LinearLayout>

Thank you very mouch for any answers. Ripityom

Ripityom
  • 426
  • 1
  • 5
  • 12
  • possible duplicate of [Load an SWF into a WebView](http://stackoverflow.com/questions/2994116/load-an-swf-into-a-webview) which appears to provide the solution. – Chris Stratton May 22 '11 at 16:49

3 Answers3

5

I've got it finally! Only needed to add the attribute

android:hardwareAccelerated = "true"

to my manifest file.

Ripityom
  • 426
  • 1
  • 5
  • 12
  • That's pretty interesting! Might I ask what device and version of Android was being used in this case? On two of my devices, swf files work without the hardwareAccelerated setting enabled. – Sven Viking May 28 '11 at 09:13
  • After several frustrating days watching a blank screen I discovered this ... android:hardwareAccelerated = "true" ... honestly...it saved my day !!! – Pedro Lobito Apr 01 '12 at 05:12
2

I just copy&pasted your code into a new project, changed the swf file location, and it worked perfectly. (The screen is blank until the .swf file finishes downloading, which can take a while in some cases).

Does your app have the INTERNET permission? The URL is definitely correct? Try with a couple of different SWF files and see if there's a difference.

Sven Viking
  • 2,660
  • 21
  • 34
0

Thx Pipityom. The attribute "android:hardwareAccelerated" save my life. Work for me as well.

Here I post the explanation from android developer document "Starting from Android 3.0, a hardware-accelerated OpenGL renderer is available to applications, to improve performance for many common 2D graphics operations. When the hardware-accelerated renderer is enabled, most operations in Canvas, Paint, Xfermode, ColorFilter, Shader, and Camera are accelerated. This results in smoother animations, smoother scrolling, and improved responsiveness overall, even for applications that do not explicitly make use the framework's OpenGL libraries.

Note that not all of the OpenGL 2D operations are accelerated. If you enable the hardware-accelerated renderer, test your application to ensure that it can make use of the renderer without errors."

Jason Zong
  • 121
  • 1
  • 6