{"id":9379,"date":"2013-01-31T12:49:02","date_gmt":"2013-01-31T07:19:02","guid":{"rendered":"https:\/\/tothenewco.pro\/blog\/?p=9379"},"modified":"2013-01-31T12:52:54","modified_gmt":"2013-01-31T07:22:54","slug":"using-sendjavscript-to-inject-javascript-into-android-phonegap-application","status":"publish","type":"post","link":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/","title":{"rendered":"Using &#8216;SendJavscript&#8217; to inject javascript into Android Phonegap application"},"content":{"rendered":"<p>In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code\u00a0will inject a variable in Javscript with value of 10.<br \/>\n[sourcecode]<br \/>\nPhonegapActivity.this.sendJavascript(\u201cjavascript:var injectedVariable=10;\u201d) \/\/PhonegapActivity \u2013 Activity that extends DroidGap class<br \/>\n[\/sourcecode]<\/p>\n<p>Moreover, as various activites in an Android app communicate with each other by using intents, the Phonegap activity can be configured to handle data sent by other activities and passing it to the Javascript by over-riding the \u2018onNewIntent()\u2019 method in Phonegap Activity. For example \u2013<br \/>\n[sourcecode]<br \/>\n@Override<br \/>\npublic void onNewIntent(Intent intent) {<br \/>\nsuper.onNewIntent(intent);<br \/>\nString data=intent.getStringExtra(\u201cdata\u201d);<br \/>\nPhonegapActivity.this.sendJavascript(&quot;javascript:var data=&quot;+data+\u201d;\u201d);<br \/>\nPhonegapActivity.this.sendJavascript(&quot;javascript:doSomethingWithData(data);\u201d);<\/p>\n<p>}<br \/>\n[\/sourcecode]<br \/>\nThus, we can intercept the event to obtain the data, then pass it along to Phonegap and process it according to our requirement in Javascript.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code\u00a0will inject a variable in Javscript with value [&hellip;]<\/p>\n","protected":false},"author":43,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":9,"footnotes":""},"categories":[518],"tags":[],"class_list":["post-9379","post","type-post","status-publish","format-standard","hentry","category-android"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code will inject a variable in Javscript with value\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Prakash Balodi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Using \u2018SendJavscript\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code will inject a variable in Javscript with value\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Using \u2018SendJavscript\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code will inject a variable in Javscript with value\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#article\",\"name\":\"Using \\u2018SendJavscript\\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog\",\"headline\":\"Using &#8216;SendJavscript&#8217; to inject javascript into Android Phonegap application\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/prakash\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2013-01-31T12:49:02+05:30\",\"dateModified\":\"2013-01-31T12:52:54+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#webpage\"},\"articleSection\":\"Android\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/android\\\/#listItem\",\"name\":\"Android\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/android\\\/#listItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/android\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#listItem\",\"name\":\"Using &#8216;SendJavscript&#8217; to inject javascript into Android Phonegap application\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#listItem\",\"position\":3,\"name\":\"Using &#8216;SendJavscript&#8217; to inject javascript into Android Phonegap application\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/android\\\/#listItem\",\"name\":\"Android\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/prakash\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/prakash\\\/\",\"name\":\"Prakash Balodi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/32f51f51cd4b1925e42b22626a4f07560afa28804014d45d2f71c58491967174?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Prakash Balodi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/\",\"name\":\"Using \\u2018SendJavscript\\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog\",\"description\":\"In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \\u2018sendJavascript()\\u2019 method available in DroidGap class. For example, the following line of code will inject a variable in Javscript with value\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/prakash\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/prakash\\\/#author\"},\"datePublished\":\"2013-01-31T12:49:02+05:30\",\"dateModified\":\"2013-01-31T12:52:54+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Using \u2018SendJavscript\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog","description":"In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code will inject a variable in Javscript with value","canonical_url":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#article","name":"Using \u2018SendJavscript\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog","headline":"Using &#8216;SendJavscript&#8217; to inject javascript into Android Phonegap application","author":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/prakash\/#author"},"publisher":{"@id":"https:\/\/tothenewco.pro\/blog\/#organization"},"datePublished":"2013-01-31T12:49:02+05:30","dateModified":"2013-01-31T12:52:54+05:30","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#webpage"},"isPartOf":{"@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#webpage"},"articleSection":"Android"},{"@type":"BreadcrumbList","@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/tothenewco.pro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/android\/#listItem","name":"Android"}},{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/android\/#listItem","position":2,"name":"Android","item":"https:\/\/tothenewco.pro\/blog\/category\/android\/","nextItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#listItem","name":"Using &#8216;SendJavscript&#8217; to inject javascript into Android Phonegap application"},"previousItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#listItem","position":3,"name":"Using &#8216;SendJavscript&#8217; to inject javascript into Android Phonegap application","previousItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/android\/#listItem","name":"Android"}}]},{"@type":"Organization","@id":"https:\/\/tothenewco.pro\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/tothenewco.pro\/blog\/"},{"@type":"Person","@id":"https:\/\/tothenewco.pro\/blog\/author\/prakash\/#author","url":"https:\/\/tothenewco.pro\/blog\/author\/prakash\/","name":"Prakash Balodi","image":{"@type":"ImageObject","@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/32f51f51cd4b1925e42b22626a4f07560afa28804014d45d2f71c58491967174?s=96&d=mm&r=g","width":96,"height":96,"caption":"Prakash Balodi"}},{"@type":"WebPage","@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#webpage","url":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/","name":"Using \u2018SendJavscript\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog","description":"In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code will inject a variable in Javscript with value","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/tothenewco.pro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/#breadcrumblist"},"author":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/prakash\/#author"},"creator":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/prakash\/#author"},"datePublished":"2013-01-31T12:49:02+05:30","dateModified":"2013-01-31T12:52:54+05:30"},{"@type":"WebSite","@id":"https:\/\/tothenewco.pro\/blog\/#website","url":"https:\/\/tothenewco.pro\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/tothenewco.pro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Using \u2018SendJavscript\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog","og:description":"In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code will inject a variable in Javscript with value","og:url":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/","og:image":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Using \u2018SendJavscript\u2019 to inject javascript into Android Phonegap application | TO THE NEW Blog","twitter:description":"In one of my Android Phonegap projects, I had to pass information from the native java code of my app to the Phonegap code(written in Javascript). I found out that I can do so with \u2018sendJavascript()\u2019 method available in DroidGap class. For example, the following line of code will inject a variable in Javscript with value","twitter:image":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"9379","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-30 08:08:02","updated":"2024-02-29 10:53:23","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/tothenewco.pro\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/tothenewco.pro\/blog\/category\/android\/\" title=\"Android\">Android<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUsing \u2018SendJavscript\u2019 to inject javascript into Android Phonegap application\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/tothenewco.pro\/blog"},{"label":"Android","link":"https:\/\/tothenewco.pro\/blog\/category\/android\/"},{"label":"Using &#8216;SendJavscript&#8217; to inject javascript into Android Phonegap application","link":"https:\/\/tothenewco.pro\/blog\/using-sendjavscript-to-inject-javascript-into-android-phonegap-application\/"}],"_links":{"self":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts\/9379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/users\/43"}],"replies":[{"embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/comments?post=9379"}],"version-history":[{"count":0,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts\/9379\/revisions"}],"wp:attachment":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/media?parent=9379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/categories?post=9379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/tags?post=9379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}