call/receive data from javascript from an android activity without web view - javascript

I created a small application using android studio. When i click a button, which is found in the action bar, I need to first call a javascript method and afterwards get the json data from that javascript method, and show the data in the activity.
I am aware that this can be done by using a web view but if possible, i need to create this without using web view.
hope someone can help me because i'm really stuck here
thanks in advance

Related

Xamarin.Forms/Asp.Net Core Custom WebView Integration

I am currently building a pizza ordering app using Xamarin.forms intended for both iOS and Android, and whilst trying to integrate with the payment provider I have encountered a very sticky situation.
Essentially the payment provider (Elavon) provides me a Hosted Payments Page(HPP) where I can send the user to complete their transaction, great. The issue is that when the user cancels a transaction or successfully completes the page will redirect to a page of my choosing, but I have no way of knowing (from Xamarin) when the transaction is complete/cancelled.
So in order to jump out of the WebView I need to call a JavaScript function from the redirected page, that will in turn invoke some C# in Xamarin to exit webview and navigate to an appropriate page.
I have successfully implemented the HybridWebView from Microsoft docs in the past, here:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview
Ideally I could navigate to a local html page in each of the platform projects as in this example, but I do not think this is possible with just a Url, which is all the HPP accepts (Additionally file locations are different on Android/iOS).
I intended to simply navigate to a webpage that I host in Asp Net core where I can call the invokeCSharpAction method, pass string data back to xamarin, and depending on string value navigate accordingly in Xamarin.
The problem with this approach is that on the web page I get an "Uncaught Reference Error" on the "invokeCSharpAction" and the function in Xamarin is NOT getting called.
Does anyone know if it is possible to invoke a C# action in Xamarin from a web page that is NOT local to the device?
Thanks in advance to anyone who has any ideas, I'm fresh out.

Cannot get form from webpage

I am trying to get the login form from:
https://www.etoro.com/login
when I inspect in Chrome I can see the element, however when I use the jaunt api in Java I cannot get the form.
userAgent = new UserAgent();
userAgent.visit("https://etoro.com/login");
List<Form> forms = userAgent.doc.getForms();
System.out.println(forms.size()); // 0
I have little experience in HTML so any direction would be great!
This is my first post so if I havent done something correctly please let me know.
Thank you very much!
Well, you are out of luck with a simple Java web scraper.
If you look at the source of the page in the browser, you see, that the page consists mainly of a long <script>. The whole login form is then created by the browser with Javascript.
If you absolutely must scrape this exact form, you need a tool, that can execute Javascript. For this, you could use PhantomJS. That's basically a complete browser, that can be controlled with a Javascript API.
Search Google for phantomjs web scraping to get you started.

Create a donwloadable content Apps with Javascript and HTML5 for Mobile Devices

Hello Everyone and thanks for taking the time to answer my question!
I want to create a simple app to display up to date information to our client. The App should check the latest "data" on the server every time the aplication start and download it to the client. That way the app will be able to use that "data" to show the information.
Does anyone know how I can do that with only JavaScript or maybe a JSON file and HTML5, or do you have any suggestion the best way to do something like that?
Thank you in advance!
You can generate JSON on yor server and parse that on the mobile device to display the data.
It's generally better to use native code instead of wrapping a HTML Application into your Android App. That way you can also use Google Material Design.
Assuming you don't want to write a separate native app for both Android and IOS, you could create a single mobile application using PhoneGap that is just a single HTML page with Javascript that does an XHR call to your server when it loads and stores the response JSON locally. PhoneGap allows you to compile versions for IOS and Android from a single codebase.
With PhoneGap there is a handler that gets called when the app loads that you can use:
function onDeviceReady() {
$.getJSON("http://yourserver/yourfile.json", function( data ) {
//do whatever you want with the data to store it
})
}

android url scheme or javascript interface?

I have a html 5 single url based app (written using slingshot), which has features of sending email to a specific date and time based on user requirements. I used android webview to access the app. The email functionality explained above need to be transferred to android local notification. Setting up notification is not the issue, the issue is how to get the web layer json data in my android native layer to set the local notification.
Not sure if I can use javascript interface as i am not going to call any method from my web app. The save button i have in my web app will trigger the json dada which i want to capture in android layer. I was thinking to user intent filter to capture the url scheme but didn't really find any good example as most of the example is showing local html file coming from asset directory. But in my case i have a html 5 single url app (written using slingshot) triggering the data when save button is getting click.
didn't really find any good references stuck here , please help.

Javascript in browser, print data to file

Im running a javascript trading application in my browser, provided by my bank. The application gives me realtime data on stock quotes etc. Is there anyway i can get the browser to make the data available outside the browser, like writing the info to a file every ten seconds? Im using firefox.
No, the Javascript is running in a sandbox. You can write it into a html5 database build in with your browser.
May be, the application is using a SOAP-Service, which you can use directly.
there is a way save the web pages. hope it will help you.
The add on is available to save web pages in mozilla.
see https://addons.mozilla.org/en-US/firefox/addon/auto-save-document/
There is a straight-forward approach, that requires a server (even if it's a very dumb one): You could post the data to the server and have it respond with a file containing the posted data (no more, no less) that the user is prompted to save.

Categories