Calling android native APIs from javascript functions of embedded WebView - javascript

I am blackberry developer and I don't have any experience in Android programming.
I am trying to create an android application which will have webview/embedded browser. I will load some web page with some javascripts in embedded browser. There will be some buttons on the page which will call javascript functions. Some of these functions require access to native APIs (eg Camera API). Is it possible to call native api's from javascript functions or access to native code of the app ?
Right now this is possible in blackberry platform using Javascript extension. I'm expecting something similar in Android.
Thank you.
Anyone who is looking for the answer, I've found solution based on #dtanders answer.
Check this out:
http://developer.android.com/guide/webapps/webview.html#BindingJavaScript

Use http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String) to expose Java interfaces to the JavaScript running in the WebView

Well, if you specifically want the Camera API, it can be done. From your JS code, you can call a piece of Java code which will in turn trigger the Camera App, take a picture, return the image's URL, which your Java code can forward it to a JS method.

See:
http://developer.android.com/guide/webapps/index.html
http://developer.android.com/guide/webapps/webview.html

Its a complete shot in the dark on my part but these might have some useful information for you.
Webview not responding to touch events
Does Android support click events in its WebView?
Also don't forget that WebViews have javascript disabled by default you'll need to explicitly set it to true in order to make it work.

Related

Accessing Google AAID via Mobile Browser (Javascript)

I've been searching online for sometime now and have yet to find a clear answer on this subject.
I would like to access a users Google AAID (Advertising ID) via my website when they access it using a mobile browser. I would think this would be possible with some javascript code but I have yet to find any.
Has anyone had experience with this? And is it possible to do?
Thanks!
Capturing IDFA/GAID from mobiles browsers cannot be done,
Apply this approach in native or hybrid app.
until today PWA also do not support
How to fetch device information from a progressive web app

Sample WebView application source code Android

I'm working on an HTML5 based Android App, and I don't understand how to get WebView working. I was wondering if anyone could point me to a place where I can download the source code for an example application of this so I can modify it for my app, or at least reference it. It needs JavaScript support, and to open links in WebView, instead of in the Browser application, which I heard happens unless you change a setting. It will access local files only, not from the internet, but might later on interface with database systems, so it needs the Internet permission, but I think I understand how to add that. Thank you!
I will suggest you too have a look on Cordova.
You can find everything to start a hybrid android app.

How can I use javascript in TWebBrowser in Delphi XE5 on all platforms (IOS,WIN,ANDROID)?

I want to use TWebBrowser on Android in Delphi XE5 to connect to google maps api.
I wrote my own component which works on WIN platform. I used Twebbrowser and IHTMLDocument2.
For example :
if Self.Document as IHTMLDocument2<>nil then
with TWebBrowser(Self).Document as IHTMLDocument2 do
with ParentWindow do
execScript(aScript, 'JavaScript');
Is Any chance to run something similar in TWebbrowser on Android (execute javaScript in TWebBrowser)?
Is any other solution?
By the looks of it according to the documentation of the Android WebView, which I currently assume (without having resource to the source) to be behind TWebBrowser, you'd need to pull out the underlying Android WebView and call its add JavascriptInterface() method (documentation here).
Whether anyone's already done that, I don't know. But that looks to be the requirement. The next step is working out how to access the underlying WebView. I'd imagine that is tucked away in the Android implementation unit for the web browser, so that will be tricky, and may require you to modify the source files.
Anyway, hopefully that gets you started.
I propose to You to use something like:
TWebBrowser.Document AS IHTMLDocument2
and then check OnKeyDown event what is the caption of all inputs objects in DOM.
Hope it helps... I'm not the God of XE5 :-)
I saw an example that wrote the static html to a local file, then loaded the local file.
WebBrowser1.Navigate('file://MyFile.html')
If you find a solution that works in iOS and Android, I'd love to hear about it.
Struggling with the same issue right now.

Writing apps for Apple platforms with Javascript

Does Apple allow iOS and Mac apps to use Javascript? Can someone give me examples of how to use it and the advantages and disadvantages?
If you're looking for a less techy solution, you could also use AppFurnace ( http://www.appfurnace.com ) to create JavaScript & HTML5 apps, packaged as native apps for iPhone and Android. We use PhoneGap (mentioned above), with an added drag-and-drop interface, enabling you to make your own apps.
You can use phonegap as a javascript, html and css wrapper in your ios app if you want to create a native app using html and javascript.
There's NimbleKit which allows you to make native apps using HTML and Javascript. Otherwise you can use a UIWebview which you can execute Javascript in. Look at the UIWebView documentation for more info.
There are tools to code your app in javascript and compile it into native code.
But if you want your app to load javascript code at runtime and run it, then see this for more details.

How to create a Firefox add-on using Objective-C on Mac OS X?

More precisely my goal is to create an add-on (or plug-in?) which is able to communicate with my main Cocoa application using something like the NSDistributedNotificationCenter. I need to be able to inject JavaScript code into the current webpage and get return values from the JS calls when my add-on receives the request to do so by my main application. Then I need to pass the return values back to my main application for processing.
Alternatively if there is a simple way to call JS in the active Firefox webpage and get return values that would also do the job.
If you want more info on why I want to do this, you can look at my other question: How to send JavaScript code to IE using C# (.Net 3.5), run it, then get a string return value from the JS code?
Note that I'm not only interested in knowing how to make a Firefox add-on but also in everything I talked about above. For example, how to inject JS into the active webpage, etc.
I'd like guidance on what technologies to use, tutorials and sample code if possible. The best would be a sample Xcode project but I'm not counting on this :P
Thanks in advance!
N.B: I'm working on 10.4.
You could try using C-Types with FF, which is a regular dll being called by Javascript in your addon, this is WAY better approach that using XPCOM, because if the Interfaces you use in there can change in each FF version, indeed you will have to do multiple dlls each for your addon supported FF versions
Go here my friend->
https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes
First learn how to write add-ons for Firefox. Adding Objective-C code afterwards is the easy part.
I know there is source available to the OSX FF Plugins for displaying download progress over the Dock Icon (http://github.com/vasi/firefox-dock-progress) and the "pdf plugin" that allows FF to do in-line PDFs is on Google Code.

Categories

Resources