I am trying to make a web browser with javafx, but I need to get the url of the website that the user is on. I tryed using getDocument(), but that didn't work, and there's no getUrl() method. Will you tell me how I can accomplish this.
Just to add onto Zephyr's answer I would like to give you the code you need:
browserName.getEngine().load("https://www." + urlFieldName.getText());
urlFieldName.setText(browserName.getEngine().getLocation());
Related
We've got application to view some specific materials. Among material types there is HTML5 presentation that is shown in WebView widget inside app. And now we need to get detailed information about this view (for example slide show duration, list element pick where it is available, etc).
It is what customer wants - we can't change it.
We decided to use IndexedDB inside HTML5 to store information locally. Now storing works (as I know :) ). Next problem is to get this information by app and it is not solved yet. Unfortunately google didn't help me.
How to get information from IndexedDB file if I know its path? Or do you know another way to transfer data from html to native app?
P.S. Writing custom browser could not be solution.
Update
Found solution to load file from JS. In chrome browser it automatically saves in downloads. In android app I'm setting to WebView object DownloadListener to listen file save event.
Catching save file works perfect. But the url path is looks like blob:file/... and I can't get info from it. Tried using ContentResolver, create File object, replace blob: string with nothing, start ACTION_VIEW intent - nothing helped.
Update
Tried to use DownloadManager and DownloadManager.Request - it throws following exception
java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: file:///fa4857ad-0e86-454a-a341-123729e9ece0
Same with blob:file uri.
Is it a requirement to use IndexedDB for communication?
If not, you could add a javascript interface. Simply pass on the data as JSON string and then decode it on the java side.
https://developer.android.com/guide/webapps/webview.html#BindingJavaScript
Mind security (don't allow the user to browse to different pages, sanitize incoming data, ...) ;-)
You can solve the problem by hack by calling the JavaScript function from Java and returning the required attributes in specific pattern. To implement this
Create the javascript function which will return the attributes in
specific pattern.
Create the WebChromClient and override onJsAlert() method. message
parameter of onJsAlert has the returned string of message. Parse the
message string to get the required attributes.
Call the JavaScript function from Java code to get the value.
final class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
result.confirm();
// Parse the message to get the required attributes
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
return true;
}
}
To call the JavaScript function to get the data use the below code. Here testFunction() is the fucntion which will return the data in string format.
webView.loadUrl("javascript:alert(testFunction())");
Create the instance of WebChromeClient and set in webview and also don't forget to enable the JavaScript.
WebView webView = (WebView)findViewById(R.id.web_view);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new MyWebChromeClient());
We decided to use ServerSocket for localhost as web server on device. And then Html sends to it http responce. May be using java script binding as wrote #Michael2 whould be better, but our solution was realized before his post. :-)
Is there any way to get the user cover photo via spring-social-facebook?
Something similar to this (used to retrieve the profile picture);
Via AbstractConnection, method getProfileUrl()
Via UserOperations, method getUserProfileImage()
Thanks for the help
From version 2.0.x you can get the cover image using
facebook.userOperations().getUserProfile().getCover()
See javadoc
I have integrated the GWT application with Chrome packaged app with help of DirectLinkerinstaller like the code below:
public class CSPCompatibleLinker extends DirectInstallLinker {
#Override
protected String getJsInstallLocation(LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/installLocationMainWindow.js";
}
}
But now I want to call print function from Chrome packaged app. When I call window.print() it allows me to print current window, but I need to open a new separate window and print that.
Could you anyone please help me in this?
I can't answer anything about GWT or DirectLinkerinstaller, but here's an answer about Chrome Apps, assuming that's what you're asking about:
You use the chrome.app.window.create API to create a window. Then, you can call the print method for that window.
In my apps, I seldom want to print what's in a window, but rather something I've generated specifically for printing. For that, I create a PDF with jsPDF (Google it), which works well. Then I display the PDF in a window, and let the user print the PDF (or save it).
I am using the the gridView example from the developer.android.com site. But they are using images saved in the res/drawable folder. I want to try and set the images to come from my web server.
private Integer[] mThumbIds={
for(int i=0;i<myJSONArray.lenght();i++){
Object[] myJSONArray;
setImageDrawable(Drawable.createFromPath(String "www.mywebsite.com: + myJSONArray[i]).thumb);
};
};
Am I on the correct path to accomplish this? I am looking for advice or documentations/tutorials on this process. Thanks in advance.
I modified the GreenDroid library to do it for me - it has a nice set of imageloading classes. It takes some slight modification if you don't want to use their actionbar (I didn't see an easy way to do it without modification). Everything is also async : D !
this way you cant create Drawable from internet, for that you have first download content & make it Drawable refer this
i am new learner of java i want to create one application program in applet. i want to create
"applet which has a Text Field to accept a URL string, and displays the document of the URL string in a new browser window."
Thanks in advance.
#nimit parekh
this post contains answer to your question:
Getting java gui to open a webpage in web browser
From inside your applet class (which must extend java.awt.Applet or javax.swing.JApplet):
getAppletContext().showDocument(new URL("http://www.google.com"));