[android-developers] Re: 1.5 addjavascriptinterface
Michael Thomas wrote: 1) window.phz is not null and is an object in my js (as before in 1.0) Don't do that. 3) window.phz.backbutton is now null (ie, the debugmsg(...) is called in the js) Don't do that either. I do not believe it is part of the API contract that the Java objects are necessarily exposed as first-class Javascript objects. I have had problems in the past with Javascript code attempting to do anything other than just calling the methods exposed by the Java objects. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android App Developer Books: http://commonsware.com/books.html --~--~-~--~~~---~--~~ 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: 1.5 addjavascriptinterface
Hmm... yes, that's odd. It's been a while, but iirc not putting it in onLoadResource() in 1.0 was giving me trouble. I'm pretty sure I went to the trouble after some googling. When I put before the loadURL (), it now works again. That's pretty bizarre behavior though. I can see not loading the object at all (ie window.phz == null) but loading an object with no methods is just plain weird. Mike On Jun 4, 4:23 pm, Mark Murphy mmur...@commonsware.com wrote: Michael Thomas wrote: Hi all, I just got my 1.5 pushed to me yesterday and it seems that WebView.addJavascriptInterface stopped working. Visit: http://commonsware.com/AdvAndroid where you will find source code to one of my books. In that ZIP file, you will find a couple of WebKit projects, both of which use addJavascriptInterface(), and both of which work fine on Android 1.5. What I have is: public class phzJSI { public void backbutton () { mHandler.post(new Runnable () { public void run () { setMain (null); } }); } private class phzWVC extends WebViewClient { public void onLoadResource (WebView w, String url) { w.addJavascriptInterface(new phzJSI (), phz); } Why are you calling addJavascriptInterface() in onLoadResource()? Why not before you load the page? -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Books:http://commonsware.com/books.html --~--~-~--~~~---~--~~ 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: 1.5 addjavascriptinterface
would it be better to just try { window.phz.backbutton () } catch () instead? this need to be cross-browser safe. I have noticed that the normally implicit .toString() js method causes chunks to be blown, so I'm not doubting you :) Mike On Jun 4, 4:28 pm, Mark Murphy mmur...@commonsware.com wrote: Michael Thomas wrote: 1) window.phz is not null and is an object in my js (as before in 1.0) Don't do that. 3) window.phz.backbutton is now null (ie, the debugmsg(...) is called in the js) Don't do that either. I do not believe it is part of the API contract that the Java objects are necessarily exposed as first-class Javascript objects. I have had problems in the past with Javascript code attempting to do anything other than just calling the methods exposed by the Java objects. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Books:http://commonsware.com/books.html --~--~-~--~~~---~--~~ 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: 1.5 addjavascriptinterface
Michael Thomas wrote: would it be better to just try { window.phz.backbutton () } catch () instead? this need to be cross-browser safe. Oof. That could be trouble. Can't you sniff on browser type and serve up the proper HTML based on whether it's an Android device? I have noticed that the normally implicit .toString() js method causes chunks to be blown, so I'm not doubting you :) If you mean that a returned string from Java is not really a Javascript string, I know what you mean. Concatenate an empty string on the Java return value to force it to become a Javascript string, where needed. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android App Developer Books: http://commonsware.com/books.html --~--~-~--~~~---~--~~ 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: 1.5 addjavascriptinterface
On Jun 4, 4:49 pm, Mark Murphy mmur...@commonsware.com wrote: Michael Thomas wrote: would it be better to just try { window.phz.backbutton () } catch () instead? this need to be cross-browser safe. Oof. That could be trouble. Well, both methods _do_ work. What do you mean by trouble anyway? And why would a try/catch block be a problem? The native method isn't what's throwing the error, it's the _lack_ of the jsi method (ie, on a non- android device). Surely the jsi method isn't disallowed from being inside a try/catch block. Can't you sniff on browser type and serve up the proper HTML based on whether it's an Android device? That's a generally frowned upon way of detecting things. I have noticed that the normally implicit .toString() js method causes chunks to be blown, so I'm not doubting you :) If you mean that a returned string from Java is not really a Javascript string, I know what you mean. Concatenate an empty string on the Java return value to force it to become a Javascript string, where needed. No, just (+window.phz) (ie, the javascript interface object's implicit .toString() method in js) causes the process to blow off. Annoying, but not a huge deal. Mike -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Books:http://commonsware.com/books.html --~--~-~--~~~---~--~~ 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: 1.5 addjavascriptinterface
Michael Thomas wrote: Well, both methods _do_ work. What do you mean by trouble anyway? If it works, cool. And why would a try/catch block be a problem? The native method isn't what's throwing the error, it's the _lack_ of the jsi method (ie, on a non- android device). Surely the jsi method isn't disallowed from being inside a try/catch block. No, that should be OK. I was not thinking straight. My apologies. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android App Developer Training: http://commonsware.com/training.html --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---