As we already know by now the HTC Hero supports Flash in the browser, and by double tapping on Flash content it will be played in full screen mode. In fact I believe that’s also the reason why we cannot use the Flash Player directly with Intents.

Those of you familiar with Nokia’s WebRuntime or the iPhone UIWebView will recognize WebView, because it’s the same thing. Really it’s an implementation of the browser framework made available as a UI component. Some of these implementations come with hooks into the platform code through JScript, and enable the use of device APIs like Location.
So what can we do with the Android browser? Let’s look at the pieces provided by Android:
- WebView – Used to load and display web pages using the built-in device browser and chrome, embedded into your application.
- WebViewClient – Enables the handling of various browser actions like page loading and error handling. Overrides the Activity in the built in browser.
- WebChromeClient – Enables the replacement of the browser chrome for events like progress, alerts and for window controls. Can override the default Chrome.
Step 1: Launch the built-in browser using WebView
The code to do this couldn’t be simpler, but there are a few extra changes to make with the layout declarative XML and with the AndroidManifest.xml. Android supports the ability to lay out the application using standard components, much like Flex.
To add a WebView to our layout we must add the WebView node to the main.xml (in project/assets/layout). You can see the id property of the node looking rather special, and that’s because it’s indicating a binding.. again, just like Flex. We can use this resource, and any others later in our code using the builtin R class.
Now we’ve done that we have to add a new permission to the Android Manifest.xml. You’ll notice that the XML includes a number of nodes pertaining to my application, most of it is easy to understand. Note also that my application has it’s own Intent and an Activity called StubApp.
With that we only need to add a tiny piece of code to use the webview component, check it out.
As before we overload the onCreate method, call the parent for good measure and then get to business. We call setContentView to build the WebView using our layout XML file above and then get a reference to this view, set JScript to enabled and load a URL. It really couldn’t be simpler and as before this runs on the device, however there are issues.
Clicking links in WebView above causes the loss of client control over the page. The result is that Flash works, but we cannot control the user experience.
The next step was to attempt to bring the control over loading new pages within the webview instance. To do this we need to extend the WebViewClient class and override the shouldOverrideUrlLoading method, this gives us the opportunity to load the page ourselves; before the browser gets to it.
It looks like this and note that return true after view.loadUrl(url) means don’t bubble this event to other web views:
The result of this is work is that we can simply replace the currently loaded page without launching a new activity, but it comes with a penalty. As when I implemented the custom WebViewClient it became clear that the Flash plugin was not being loaded. Worse still, there’s no way to load it (despite APIs to the contrary) and that’s by design at this time.
So there you have it, the investigation into creating a Flash Application that lives in the browser can only succeed when using the native browser. The Android Platform allows for the creation of custom browser clients and chrome, but the penalty for this is that you loose access to plugins.
Hopefully this has been an informative post, and maybe inspired you to have a look at Android with Flash Player support. Maybe you can extend my examples, or by all means provide some secret code that can help us start up the plugins

#1 by Weyert on August 13, 2009 - 11:18 am
Thanks for your articles. This is the same way how PhoneGap does his tricks for the iPhone. Similar approach. And yes, it would be nice if this WebKit instance would have plug-ins enabled that would be nice!
#2 by Li yong fei on August 14, 2009 - 4:51 am
Good article, Thanks Mark!
#3 by Alex on August 20, 2009 - 11:07 pm
Hi Mark,
I’m trying to put together an App that includes Flash content run from a Webview and can confirm the same thing – no Flash.
There are two methods that I found that might be part of the solution
setFlashPlayerEnabled() – HTC Hero only . . . needs to be run through reflection, and doesn’t work on its own
setPluginsPath(String) – this needs a path to the plugin
#4 by Mark Doherty on August 21, 2009 - 8:01 am
Interesting, and was setFlashPlayerEnabled() part of the WebView class?
#5 by Alex on August 21, 2009 - 4:18 pm
I’m calling it on the WebSettings object of the webview – apparently it is part of the HTC builds,
http://forum.xda-developers.com/showthread.php?t=521221
It’s not enough on its own though. I’m still getting the ‘missing plugin’ box.
#6 by Mark Doherty on August 23, 2009 - 3:46 pm
How did you call the setFlashPlayerEnabled method? I believe it’s private/protected?
Java’s reflection API doesn’t work since it was closed in 1.1
#7 by Alex on August 24, 2009 - 12:41 pm
Here’s some code – let’s see if makes it through okay . . .
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setPluginsEnabled(true);
//mWebView.getSettings().setPluginsPath(“?????”);
//Try to Call Set Flash Player Enabled
Boolean[] input={new Boolean(true)};
try{
Class cl=Class.forName(“android.webkit.WebSettings”);
Class[] par=new Class[1];
par[0]=Boolean.TYPE;
Method mthd=cl.getMethod(“setFlashPlayerEnabled”,par);
mthd.invoke(mWebView.getSettings(),input);
//mWebView.loadUrl(“file:///android_asset/index.html”);
mWebView.loadUrl(“http://www.questionwritertracker.com/index.php/quiz/display?id=1634&token=6P3DTKGE”);
}catch(Exception e){
mWebView.loadUrl(“http://www.google.com/”+e.toString());
}
#8 by Alex on August 24, 2009 - 12:47 pm
Okay, looks good. Here’s what I’m seeing.
On the emulator, I’m getting a ‘Method Not Found’ Exception.
On the HTC Hero, I think it is calling the method, but I’m still getting the ‘missing plugin’ icon.
#9 by Mark Doherty on August 24, 2009 - 6:07 pm
Hmm, so it doesn’t fail on the device and seems to be calling the function. However I see the same resulting icon which seems to indicate that the Flash Plugin isn’t active in WebView.
Nice bit of code by the way
#10 by Zarate on September 9, 2009 - 12:37 pm
Hi!
Nice 2 articles, they are going to be very helpful in the near future : )
For the time being, is it possible to launch the stand alone player installed (reported in Applications as HTC Flash Player) and open a SWF from the SD card?
I’m basically looking for a way to test a Flash app on my Hero.
ta!
#11 by jade on September 15, 2009 - 10:28 am
Hi!
My question is, that if I want to create an app, that I publish on Nokia or Windowsmobile devices with Adobe packager, which solution should I use: filepicker or webview?
Are there any differences, like no webconnection in standalone mode etc.
#12 by HO on October 5, 2009 - 4:26 pm
Interesting, and was setFlashPlayerEnabled() part of the WebView class?
#13 by Nik Bhattacharya on November 18, 2009 - 8:45 pm
It is possible to launch the the HTC file browser to list all of the flash files on your SDCard. Create a generic android project and in the generated class, insert the following code:
Intent flashIntent = new Intent(Intent.ACTION_MAIN);
flashIntent.setClassName(“com.htc.flash”,”com.htc.flash.FlashPlayer”);
startActivity(flashIntent);
Mount your SDCard onto your computer. Develop your flash app, move it to the SDCard, and relaunch the app. Voila! You have the FlashPlayer.
Right now, I am not able to figure out how to get the FlashPlayer to remain in portrait mode. It looks like it is getting forced into landscape. Trying to figure it right right now.
I have found that there is an Activity called com.htc.flash.SingleViewActivity that is in the com.htc.flash application that possibly has the emdedded flash player running in full screen mode. Trying to see if I can launch that activity directly using Intent. I still don’t know what the required Intent.Action is and how it takes the URI of the SDCard flash file as its Data argument.
Nik Bhattacharya
frog design