JavaFx WebView not updating XmlHttpRrequest background data - java

I'm trying to display website with dynamic XHR (push) data in JavaFx WebView for example:
http://finance.yahoo.com/q?s=^gdaxi
http://www.boerse-frankfurt.de/en/start (data in header)
and many others. Probably not only stock exchange websites.
Each of these websites after first rendering is not updating. I checked in Wireshark and some new data are sending from the server for all the time, but without any changes in view.
I was trying to compile and run in new Java 8 but sill the same.
Any ideas?
Maybe u know some other good Web Browsers written in Java?

You haven't posted your code, but are you doing the your
webView.getEngine().load( ... );
inside Platform.runLater, e.g.?:
Platform.runLater(new Runnable() {
#Override
public void run() {
//Update here
webView.getEngine().load( ... );
}
});

Related

Can you implement autorenewing subscriptions in codenameone without a server side

I have followed the Auto renewing app subscriptions documentation. However the app i am building does not have a server side right now as it stands. I am failing to see if its possible to create the app without the need for the database at all
I have tried simply calling the Purchase.subscribe methods without any saving to a database
public void start() {
Form hi = new Form("Hello World");
//create receiptes store
Purchase.getInAppPurchase().setReceiptStore(createReceieptsStore());
//create a button to purchase the world
Button buyWorld = new Button("Buy World");
buyWorld.addActionListener(e -> {
if (Purchase.getInAppPurchase().isSubscribed(SKU)) {
Dialog.show("Cant Buy It", "You Own It", "OK", null);
} else {
Purchase.getInAppPurchase().subscribe(SKU);
}
});
hi.addComponent(buyWorld);
hi.show();
}
I got an error pertaining to the receipt store fetch and submit methods needing to be implemented
It should be possible to implement subscription without a server but it would be very easy to hack this on any rooted Android device.

Recording data in android app and web service at same time

Is it possible to record data in android app and webservice at same time? I am trying to do this but if data is recording in android app data then not recording in webservice and if recording in webservice stops recording in android app? Thx in advance
You're doing a network request on the main thread which is not supported by the Android Version you're using.
Why not ? Assuming we are doing network operation on a button click in our application. On button click a request would be made to the server and response will be awaited. Due to single thread model of android, till the time response is awaited our screen is non-responsive. So we should avoid performing long running operations on the UI thread. This includes file and network access.
So start a new Thread when you want to send data. Something like :
new Thread(new Runnable() {
#Override
public void run() {
//Send Data to Web Server Here.
}
}).start();

comunication between Web browser and java

I Am developing a private web site in PHP-html / Ajax and a client program in Java.
I have just seen that apple can, by Firefox or other, open iTunes to load content.
I want to do the same or better:
I try to make a program which can “talk” to javascript or just write a lockFile (tempfile) and so get data through this one, i try to get at least a communication Web browser - > java, but i'd rather if possible a bi-directional communication.
So if somebody have any solution, it’s will be great cause I googlised it, i tried local Storage in html5, File access in javascript … nothing really works and I don’t want the program to ask the server Avery time.
You can do this in a number of ways but you must have in mind the cross-domain restrictions. I've been doing this with sockets.
1 - You need a bridge to comunicate your web with your server this could be done with a java applet or a flash socket bridge so that you can call your server and your javascript client code.
2 - You need url-redirect rule in your server so that when your client makes a request it always makes it in the same domain but gets where your socket server finally is. You client can't go to a different domain but your server can. This is needed to skip the cross-domain restriction.
I hope this helps.
You can take a look at JxBrowser library that allows embedding Google Chromium engine into Java Swing applications. You can use this library to embed Browser component into your client Java application and load your PHP web page, like iTunes loads App Store.
It provides API for two-way communication Java-to-JavaScript-to-Java: http://www.teamdev.com/downloads/jxbrowser/docs/JxBrowser-PGuide.html#javascript-java-bridge
The following code demonstrates how to embed Browser component, load URL, invoke JavaScript code on the loaded web page and register Java function on JavaScript side that will be invoked every time when JavaScript invokes it:
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserFactory;
import com.teamdev.jxbrowser.chromium.BrowserFunction;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
/**
* The sample demonstrates how to register a new JavaScript function and
* map it to a Java method that will be invoked every time when the JavaScript
* function is invoked.
*/
public class JavaScriptJavaSample {
public static void main(String[] args) {
Browser browser = BrowserFactory.create();
// Register "MyFunction" JavaScript function and associate Java callback with it
browser.registerFunction("MyFunction", new BrowserFunction() {
public JSValue invoke(JSValue... args) {
for (JSValue arg : args) {
System.out.println("arg = " + arg);
}
return JSValue.create("Hello!");
}
});
// Create JFrame and embed Browser component to display web pages
JFrame frame = new JFrame();
frame.add(browser.getView().getComponent(), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
// Register Load listener to get notification when web page is loaded completely
browser.addLoadListener(new LoadAdapter() {
#Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
Browser browser = event.getBrowser();
// Invoke our registered JavaScript function
JSValue returnValue = browser.executeJavaScriptAndReturnValue(
"MyFunction('Hello JxBrowser!', 1, 2, 3, true);");
System.out.println("return value = " + returnValue);
}
}
});
browser.loadURL("about:blank");
}
}

Running application while idle for Android

I was wondering if there is a way to keep running my application (which basically just refreshes a URL every X seconds) even when the phone idles/locks? (when the screen turns off). I'm currently using a WebView to load the URL, and a Runnable to reload it.
When I tried using a service, it keeps giving me a problem - webview cannot be resolved. I looked it up, and I couldn't get it fixed.
I would also like to know if there is a way to browse a URL in the background. Basically, browsing a URL without showing the browser :D
Any help would be much appreciated!!!
Sorry if these questions are dumb, I've only started Android programming for a few days.
You do not need a webview to poke web server, unless you like to display results imeediately.
You can use built in http client for this purpose ( works from service and does not vae user interfce)
I think Timer task will solve your problem.
Timer timer=new Timer();
timer.schedule(new DelayedTask(),1, 1000);// it will repeat within 1000ms
private class DelayedTask extends TimerTask
{
#Override
public void run() {
runOnUiThread(new Runnable() {
#Override
public void run() {
webview.loadUrl(url);
}
});
}
}
#Override
public void onDestroy()
{
super.onDestroy();
timer.cancel();
}

jQuery webcam refresh. Wait for request to finish

As I talk about befor I'm using to jQuery to refresh / update a webcam image.
This works just fine if you wanna update the image every 5th or 10sec.
But when your gonna do a stream with 10-15fps it gets into problems with most browsers
it seems. The problem seem to be that it sends a request befor the first one was done.
Is there a way to wait for the first request to be done befor sending a new update request for the webcam image? Because to me it seems to stack up requests if there is alittle delay on the server with the image.
Sorry if I did explain it alittle bad but... I'm norwegian and blode. Not the best combination. :)
Webcam Image is a single url
ex. http://www.ohoynothere.com/image.jpg
Old code I use.
$(document).ready(function() {
setInterval('updateCamera()',3000);
});
function updateCamera() {
$('.online2').each(function() {
var url = $(this).attr('src').split('&')[0];
$(this).attr('src', url + '&rand=' + new Date().getTime());
})
}
Definitely!
It sounds like your best bet would be to use the jQuery.ajax() method ( http://api.jquery.com/jQuery.ajax/ ) or .get() method to chain your requests. Basically, you want a JavaScript function that does a request for the image using the .ajax() call. In the response handler, simply call the function again:
function getMyImage() {
jQuery.get(image_url, function(response) {
jQuery('#img-name').attr('src', response);
getMyImage();
});
}
Whenever getMyImage successfully returns the image's src value from the webcam, it will immediately go out and try to retrieve a new image, but not before the previous one is loaded.
If I haven't understood what you're trying to do, please let me know. It would be helpful to know more about how the webcam image is retrieved (i.e. is it the same image src returned every time, etc.).

Categories

Resources