Thursday, February 14, 2013

What's New in PhoneGap Android 2.4.0

Well PhoneGap 2.4.0 has been released. So here are couple of the new things you can look forward to:

1. Support Reading Slices of Text Files.

The File object now has a slice method. Suppose the file we're reading contains the text:

"All that is gold does not glitter, not all those who wander are lost." 

Then...

  • f.slice(4, 8) would result in "that" 
  • f.slice(9) would be "is gold does not glitter, not all those who wander are lost." 
  • f.slice(-5, -1) would be "lost"


2. Added input type=file support

Now if you specify an input field of type file you will get a "Choose File" button:


Then when you click the button you will launch an intent that can handle file picking:


Now the value of your input tag will be the file you selected.

3. Additional preferences in config.xml

I completely missed this one so Joe Bowser wrote it up.

10 comments:

Gjoko Grkov said...

Hello Simon,

I am using cordova 2.4.0. I am trying open pdf/ppt/doc files that are stored in my Android phone filesystem through a phonegap application using the InAppBrowser, but no success there. Is it actually possible to do it this way?

The code line I use for this is:

window.open('file:///mnt/sdcard/file.pdf','_blank','location=yes');

Any suggestions of how to do this?
Thank you in advance.

BR,
Gjoko

arjun t raj said...

hi, Android Back button not working when we open INAppBrowser in Android ICS tablet...

Plz help me

Simon MacDonald said...

@arjun t raj

Reproduction scenario?

Simon MacDonald said...

@Gjoko Grkov

Try using:

window.open('file:///mnt/sdcard/file.pdf','_system');

instead. The InAppBrowser doesn't have the facility to view PDF files.

Gjoko Grkov said...

Hello Simon

Thank you for your reply.

I tried what you suggested but I received this error message:

No Activity found to handle Intent
{act=android.intent.action.VIEW dat=file:///mnt/sdcard/file.pdf}

Do I need to change or add something in the ActivityManifest.xml ?

PS: I am also trying to open ppt files as well.

Simon MacDonald said...

@Gjoko Grkov

You need to have apps installed that can handle that mime type and are registered to view them.

Arvind Menon said...

Hi Simon,

Thanks for adding the file input feature.

Is there a way for this to respect the "accept" attribute?

input id="photo-load" type="file" accept="image/jpeg" capture="camera"

The intent that is fired seems to be a generic file intent and ignores the mime type specified.

I also noticed that cordova does not provide the camera as an option for file input. Is there a way to get around that without using the camera plugin?

Thanks!

Simon MacDonald said...

@Arvind Menon

Not yet, hoping to some good news with the Google IO going on right now.

jcesar said...

Hi Simon,
I think the input type=file support is broken on android 4.4.

Can you check it?

Simon MacDonald said...

@jcaesar

Yes, definitely broken with the new Chromium WebView.

https://issues.apache.org/jira/browse/CB-5294