[android-developers] Re: Java script to Native Bindings & reverse

2011-08-15 Thread IcedNet
You can pass simple data types (String, int), objects will not
translate. -- JSON should be fine as (key, value) or multiple comma
separated values
for example, I pass xpath and offset info regularly like so:
String startXPath,endXPath,uniqueID,highlightStyle;
int startOffset, endOffset;
final String paramString = "'" + startXPath + " ', "
+ startOffset + ", ' " + endXPath + " ', " + endOffset + ", ' "
+ uniqueID+ " ', ' "+ highlightStyle + " ' ";
_webView.loadUrl(JAVASCRIPT_HOOK + "GLOBAL.performHighlight (" +
paramString + ")");

where JAVASCRIPT_HOOK = "javascript:"

if you are passing int primitives, use no quotes (hopefully the
formatting of the web post isn't screwing up the code above too much),
for Strings, be certain to include single quotes in your call from
Java

Coming back from JavaScript, you only receive String values, so pipe
or comma-delimiting is the way to go (ie  "primitive0|primitive1|
primitive3" etc)

Peace,
Dan

On Aug 15, 12:29 pm, Mark Murphy  wrote:
> On Mon, Aug 15, 2011 at 12:26 PM, Android Developer
>
>  wrote:
> > But need little more clarity, if I need to pass objects or data with
> > complicated data types from Java to java script as arguments in
> > callback. Would JSON suffice the purpose or is there any other
> > solution ?
>
> > Checked Bookmarklets, we can call JS callbacks but that doesn't throw
> > light on argument data types issue.
>
> It has to be valid JavaScript source code. There is nothing more to it
> than that.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android App Developer Books:http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Java script to Native Bindings & reverse

2011-08-15 Thread Mark Murphy
On Mon, Aug 15, 2011 at 12:26 PM, Android Developer
 wrote:
> But need little more clarity, if I need to pass objects or data with
> complicated data types from Java to java script as arguments in
> callback. Would JSON suffice the purpose or is there any other
> solution ?
>
> Checked Bookmarklets, we can call JS callbacks but that doesn't throw
> light on argument data types issue.

It has to be valid JavaScript source code. There is nothing more to it
than that.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Java script to Native Bindings & reverse

2011-08-15 Thread Android Developer
Thanks Mark,

But need little more clarity, if I need to pass objects or data with
complicated data types from Java to java script as arguments in
callback. Would JSON suffice the purpose or is there any other
solution ?

Checked Bookmarklets, we can call JS callbacks but that doesn't throw
light on argument data types issue.

Thanks in Advance.
PS

On Aug 12, 6:53 am, Mark Murphy  wrote:
> On Fri, Aug 12, 2011 at 2:57 AM, Android Developer  
> wrote:
> > I am working on web applications where am trying to access Native
> > functionality in the phone using Java script APIs.
>
> > Android Web view supports Add Java script interface for Java script to
> > Java (native) bindings as in below link:
>
> >http://developer.android.com/reference/android/webkit/WebView.html#ad...,
> > java.lang.String)
>
> > BUT if I need to pass data back to Java script there is no API or
> > mechanism to do so.
>
> Sure there is.
>
> > Could you please let me know if there is a way out, tried hard but
> > seems no API exposed for the same.
>
> Call loadUrl("javascript:..."), where the ... is your JavaScript
> source code. That JavaScript source will be executed in the context of
> whatever Web page is presently loaded. This is the same technique that
> "bookmarklets" use.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> _The Busy Coder's Guide to *Advanced* Android Development_ Version 2.0
> Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en