Android: Javascript not working in WebView

I thought I had the wrong HTML, the wrong file paths, disabled internet connection, setting a WebChromeClient and setting the HTML doc-type to be STRICT.

In the end, I was just missing a vital call to enable it.

Allow JavaScript in your WebView by calling:


How embarassing =P


Source: Using Android’s WebView, WebChromeClient and WebViewClient to load a webpage and display the progress

Android: How to select a file

An often useful feature is the ability to choose a file to fiddle with, may it be a photo, a music file or a text file.

To kick it off, we need to start an activity with an intent of ACTION_GET_CONTENT.

public class ActivityTestActivity extends Activity {

public void onCreate(Bundle savedInstanceState) {

Button btn = (Button) this.findViewById(;
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent chooseFile;
Intent intent;
chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
intent = Intent.createChooser(chooseFile, "Choose a file");
startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
if (resultCode == RESULT_OK){
Uri uri = data.getData();
String filePath = uri.getPath();

NOTE: If you're constantly getting "No applications can perform this action", even with FileExpert or ASTRO installed, then you need to give your emulator some space in "/sdcard" to work with.

So what this code does is:

  • Creates an intent to get some content.
  • Gives the choose a title of "Choose a file"
  • Kicks off the file chooser activity with the ID of ACTIVITY_CHOOSE_FILE (1).
  • When the activity returns with a result, we need to check if it was a valid result with RESULT_OK.
  • After you get the filePath out of data.getData().getPath() and you can begin working with the file.


Keep rollin' speed-demon!

Source: choose a file from device and upload it to page loaded in the webview

Android: Display local image/CSS files in HTML with WebView

Displaying custom HTML in a WebView is pretty easy, as explained in a post I made long ago in 2009.

However, if you want to spruce it up with some images and CSS, you'll have to tweak it a little. Don't worry, it's not hard at all!

Here is an example that's a bit more verbose.

WebView wv = new WebView(this);
StringBuilder html = new StringBuilder();


html.append("<link rel=stylesheet href='css/style.css'>");
html.append("<h1>Some Heading</h1>");
html.append("<p>Some HTML content</p>");
html.append("<p><img style='width: 100%;' src='spidermen.jpg' /></p>");

wv.loadDataWithBaseURL("file:///android_asset/", html.toString(), "text/html", "UTF-8", "");

Now you'll be able to see that it has links to "css/style.css" and "spidermen.jpg". This files will be included as part of your application, not hosted on the web somewhere.

To access them, you can specify a full path "file:///android_asset/spidermen.jpg" or set the baseURL for the WebView to be "file:///android_asset/".

Now to put the files in the right place.


And that's pretty much it!

Running it in the emulator will show you THIS!


Source: WebView with custom HTML and local images

Create a playlist on an MTP device

If your device supports MTP (drag and drop using Windows Explorer), then it's likely you're wondering how to create a playlist without any extra software like Songbird, iTunes or Windows Media Player.

I personally use Songbird to sync music to my Sansa c250, but for those who don't want to do that you can still use Windows Explorer to create playlists.

  • Go to Windows Explorer and select the songs you want.
  • Right click on the files and select "Create playlist"
  • Name the playlist.
  • That's all :)

You should be able to do this starting from Windows XP and onwards.

Aww don't be so shocked that it's such an easy task!

Source: Sansa e250 playlist help

CSS: Easy cross-browser compatible rounded borders/corners

Most new browsers now support the rounded borders CSS3 attribute.

However, during the drafting period, it was all done differently. To properly support these browsers, you'll need some extra styling rules to make it work.

The way I do it is less compatible but uses no hacks such as external .HTC files or browser specific CSS files because I dislike these solutions.

The rounded borders should be supported natively (with prefixes) from Firefox 1.0, Internet Explorer 9, Opera 10.5 and Chrome/Safari 3.

The magic

I like to separate my proper classes from the "compatibility" tweaks. The tweaks I normally put at the end of the file but with a matching selector name.

.tooltip {
border-radius: 3px;

.tooltip {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-khtml-border-radius: 3px;

As you can see, the later ".tooltip" definition adds prefixes for Mozilla, Webkit (Chrome/Safari) and Konquerer. {
border-top-right-radius: 5px;
border-top-left-radius: 5px;
} {
-moz-border-radius-topright: 5px;
-moz-border-radius-topleft: 5px;
-webkit-border-top-right-radius: 5px;
-webkit-border-top-left-radius: 5px;
-khtml-border-top-right-radius: 5px;
-khtml-border-top-left-radius: 5px;

Just a little something to watch out for, the earlier versions of Mozilla has their syntax as "radius-topright" rather than "top-right-radius" like the other browsers do.

Also, if rounded borders aren't working on IE9, please see this post regarding the X-UA-Compatible tag.


ATI: Disable spamming of system event logs by ati2mtag DVD_OV UVD Information

If you've ever taken a quick glance at your Event Viewer, you may notice a shitload of messages from ati2mtag.


To disable this ridiculous debug spamming, run:

  • reg add HKLM\SYSTEM\CurrentControlSet\services\Atierecord /f /v eRecordEnable /d "0" /t REG_DWORD
  • Reboot.
  • You may have to do that every time you install a new driver.

Source: Thousands of ati2mtag event 62464s (DVD_OV UVD Information) in System event log

Billion 7700N: No ping reply from WAN

I'm not quite sure why this is disabled by default, but I never seem to get a ping response from my router when checking from work.

When checking at home on the internal LAN, it works fine.

I kept poking around the firewall settings but nothing was there.

Then I stumbled across "Access Control" hidden away under "Management".

Click on "ICMP" to enable it under the WAN column.

That'll do the trick just fine!

BiPAC 7700N

You should now be able to ping your router from the internet.

Windows: How to check the original install date

This was a bit of a doozey for me, but very simple to find out.

Go to a command prompt window and type "systeminfo"

This will spit out a whole heap of info. The "Original Install Date" line is what you're after, somewhere near the top.

If you've got a lot of patches installed, it'll flood that line off the screen.

To prevent that, save the output to a file instead.

Type "systeminfo > output.txt". When it's done, open up the file.

Almost as easy as bringing dead squids back to life with soy sauce


Django: Display a field specific error in your Form/ModelForm

Django forms are incredibly flexible, but they're also a little cumbersome when it comes to errors.

The following example shows you that you can display an error for:

  • a specific field
  • a specific field from another field
  • the form as a whole
class EventForm(forms.ModelForm):
class Meta:
model = Event

title = forms.CharField(required = True)
lawyer = forms.CharField(required = True)
when = forms.CharField(max_length = 10, min_length = 10, widget = DateInput(format="%d-%m-%Y"))

def clean_when(self):
value = self.cleaned_data.get(field_name)

if value:
value = datetime.datetime.strptime(value, '%d-%m-%Y')
except ValueError:
value = None
# Displays an error under the title field, even though it's validating as the "when" field.
self._errors['title'] = ['Invalid date given.']

return value

def clean_lawyer(self):
# Display error for the lawyer field
raise forms.ValidationError("OBJECTION!")

def clean(self):
data = super(EventForm, self).clean()

# In the clean() even, errors raised will display as an error for the form (non field error)
raise forms.ValidationError('Just for the hell of it.')

return data

Raising an error is the preferred way of doing things, but if you need to do multi-line errors then it's possible to use the self._errors method.

How many errors can you see here?

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog