Run Java function on page change in Phonegap - java

I've got an Android Phonegap app that takes a website and injects a few new libraries and stylesheets (zeptojs angularjs etc.)
In my specific case I cannot simply re-write the code to JavaScript on the page (as I'm not the one in charge of the page's scripts), instead I'd like to use the Java function sendJavascript(), and run it from a Java timer object.
But no matter how I call sendJavascript it never seems to do anything.
eg:
myActivity.this.sendJavascript("javascript: alert(1)");
But alert(1) never actually fires

To call the java function from javascript you have to write a phone gap plugin. Then in the change page handler you call the javascript function from the plugin.
Can you give more details on what the alert is all about? Does it relate to the java function that you want to call previously, or is something that you want to notify from the native side?

Related

Launch IE browser in JAVA and using POST method

We have a Java awt desktop application on Windows machine. We have provided a button with hyperlink to third party web based application .
Click on button should do following :
Launch new instance of Internet Explorer on the machine.
Open the URL of third party application in IE
Submit few parameters and their values using http "POST" method in IE.
It will open the application in Browser and user will work in new Window with no further interaction with Java application.
We are able to achieve this using java.awt.Desktop.browser in "GET" method . But due to security restrictions we are not supposed to pass these parameters using GET method as they are visible in URL.
I have received some suggestions to do this by using intermediate vbscript but can it be achieved within Java .
Unfortunatelly I cannot help you with invoking IE with POST and to be honnest not sure if it is even possible via vbscript. But if you have some vbscript capable of doing such thing, you can allways invoke it from java see commons-exec library. By platform invoke you can also invoke any platform special stuff - see JNA in https://github.com/java-native-access/jna
But maybe another approach - why not use encryption and hmac verification of your parameters ? When you carefully use them, you can use GET also.

Call Applet methods from outside the browser

Here's the overall flow of the use case:
User navigates to page with a third party applet
Another program sees that the browser URL has changed and fires a custom Java app that I have written.
That custom app needs to be able to call methods on the Applet
Is it possible to call the Applet from an application outside of the browser?
I've seen lots of questions and answers around calling applets from JS in the page, but that not the case here. That being said, however, if it were possible to inject JS into the page at runtime and have THAT make the call to the applet, that might be a workaround.

SWT Browser - Detect Ajax Calls

I'm using SWT.Browser (java) and am wondering if there's a way to get a listener that hears when ajax requests are made, received, etc.
Is there a way to intercept them and manipulate them before they come in, etc?
No, there is no publicly available API for that.
However, you can write APP plugin for SWT, though it is applicable to IE only. Or for Firefox or Webkit or IE you can write a local proxy like fiddler.

Block all other input to an application and control it from a wrapper in Java

I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also, how can I automate key presses and clicks to the application without hijacking the mouse? Is this possible in Java?
I have looked at java.awt.Robot, but it appears to hijack the mouse.
I have also looked at AutoIT, but it too hijacks the mouse and does not integrate with Java.
Neither of these options seem powerful enough for what I need, but I do not know how else to proceed.
I recommend that automation via the GUI only as the last resort if you really have no other alternative.
If there is an API that your application exposes, I would try to use that. For example, if the GUI is implemented in one DLL and the logic in another, then you can use JNA to load your application logic DLL and invoke the application functions directly from java. Even better would be if your application exposes a COM/OLE interface - there are plenty of Java<>COM briges, that will alow you to call this interface directly, e.g. Jacob.
If you really have no choice but to automate via the GUI, then here's how to go about doing that:
Use JNA to access the windows shell API. You can then use ShellExecute to launch your wrapped application. Specifically, passing SW_HIDE as the window mode should help ensure that the application does not appear.
Use JNA to access the windows API FindWindow to find your application window. You can also make it invisible using the ShowWindow API, just in case step 1 did not work (not all applications are written to use the nCmdShow parameter.)
You can now post messages to the application window using PostMessage. You can send keystrokes and mouse events using windows messages. E.g. See WM_KEYUP, WM_LBUTTONDOWN.
Because the wrapped application window is made invisible, you don't need to "block" that application, The user simply cannot access it's GUI. But you can still programmatically send input to it.

JavaFX Applet web-page refresh and close notifications

How do I detect when user closes(navigates away) or refreshes web page with JavaFX applet in it? I want to do some clean up in my code on those events.
Java Applet had some callback methods to do that, but how would I do it in JavaFX running in browser?
Two steps:
You may need to use a Javascript's window.onunload event to tell your JavaFX app to "close". If you do this, you can then
Add FX.addShutdownAction(myfunction); to your run() function. This will execute myfunction when your app is closed.
I don't have some complete code for you here, but I hope it's a start. You may not need to do step 1.

Categories

Resources