I'm writing up a quick tutorial on how to get the ChildBrowser plugin for PhoneGap Android installed as a few folks on the mailing list are having troubles getting it going. First lets start off with a stock PhoneGap Android project in Eclipse:
Step one is to create the directory structure for the ChildBrowser.java file. Click on the src folder then right mouse click or control click on the folder. From the popup menu select New and Package.
In the dialog box that appears type in com.phonegap.plugins.childBrowser then click the Finish button. Please note the package name is case sensitive so make sure it matches exactly.
Step two is adding the ChildBrowser.java class to your project. Download the file from this link and save it in your projects src/com/phonegap/plugins/childBrowser directory. Then click on you projects name then right mouse click and select Refresh. Your project explorer should now look like this:
You shouldn't see any red exclamation marks at this point. If you do you've probably named your package incorrectly.
Step three is to add the childbrowser.js file to your project. Download the file from this link and save it in your projects assets/www directory. Then click on you projects name then right mouse click and select Refresh. Your project explorer should now look like this:
In step four we will need to modify the AndroidManifest.xml file to add an intent filter for the ChildBrowser. Paste the following lines inside the <application/> tag:
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name">
<intent-filter>
</intent-filter>
</activity>
Here is a gist of what my AndroidManifest.xml looks like.
In step five we need to modify our index.html file to a reference the childbrowser.js and call the ChildBrowser. In the <head/> tag after the reference to phonegap.0.9.5.js add the following line:
<script type="text/javascript" charset="utf-8" src="childbrowser.js"></script>
and somewhere in your <body/> tag add a line like this:
<a href="#" onclick="window.plugins.childBrowser.showWebPage('http://www.google.com');">Open Google.com in child browser</a>
This will give you an app that shows you this:
and opens Google in the ChildBrowser when you click on the link.
The full gist of my index.html is available as well.
Hope this helps everyone!







21 comments:
Hello,
I was following your tutorial but on clicking on the link nothing happens.
In logCat I can see those errors:
-ReferenceError: Can't find variable: PhoneGap in childbrowser.js
-TypeError: Result of expression 'windows.plugins' [undefined]
So I suppose that linking with the plugManager is not working.
Any Idea?
Are you sure your child browser.js comes after the PhoneGap.js? Also what version of PhoneGap are you using?
I have the same problem with PhoneGap 0.9.5.1.
Nothing happens. Can't see any errors either.
Hi,
when I run the App i recive the error:
Error: Status=2 Message:Class not found at file...
using phonegap 0.9.5.1
@Tobias I need some more info than that to figure out what is going on. You are probably better off taking this type of discussion over to the PhoneGap Google Group.
Thank you very much for this tutorial!
I haved the same problem : nothing happens!
And I found that in Build Path->Source->com.phonegap.plugins.childBrowser are excluded !
Is the ChildBrowser on Android supposed to show the native addressbar? Im not sure how this works on Android, but on the iPhone version it doesn't show the default address bar in the top. I can't find any video of how it is supposed to behave, so I'm not sure if its intentional.
I have uploaded som images here:
http://art-journal.dk/work/screen1.png
http://art-journal.dk/work/screen2.png
http://art-journal.dk/work/screen3.png
Any help would be much appreciated.
Kind regards,
Casper Knudsen - Art-journal.dk
Hey Casper, yes, the address bar on top of the ChildBrowser is intentional. The Android and iOS versions are not exactly the same.
Hi Simon,
Can you show an example of using the ChildBrowser plugin to post on Facebook wall in Android. There is an example for FBConnect in iOS, but not for Android.
Any help in this will be highly appreciated.
Thanks.
@Mahendra look for the FBConnect plugin as it will do what you want. Dave Johnson of Nitobi demoed it at PhoneGap day last Friday.
Hi, Simon
thanks for this tutorial. And also the tutorial on the installing PhoneGap 1.0. However, I found out that I need to use a second argument (boolean true) for showWebPage if I want it to show it on the PhoneGap app directly. At least for the latest ChildBrowser plugin it needs to use it. Thanks. :)
Hello ,
How to I call the android activity through the phonegap javascript, it is possible or not ,if possible means please give me a solution
thanking you
kumarp
@kumarspk
This is a question best posted on the PhoneGap Google Groups but if you are looking to call an intent from JS you can use the Web Intent plugin.
sir,
One more question How to i call android java class method using javascript in phonegap
Read up on how to write a plugin.
So please, can anybody help, how to hide address bar in ChildBrowser?
Hai Simon MAc,
Thanks for the coding...
I used this one, but it is working fine in emulator, it is not working inmy samsung galaxy pop.... what is the problem?
@Jithin
Need some more details.
How did you get the ChildBrowser window to appear full screen vs. as a modal dialog?
@Mitch
If you use showWebPage it uses the modal dialog with an embedded web view. If you use openExternal it starts a separate browser using an intent.
Post a Comment