I'm trying to make a program similar to Windows Photo Viewer, the program that pops up usually if you double-click an image in Windows. I've already made my own program, however it uses a JFileChooser associated with a button to bring up images to open inside the application itself (Windows photo app doesn't seem to do this).
Question:
How can I make my application handle certain file types when its double-clicked from Windows? My guess would be something along the lines of my main class having a Path/String type argument of the file I want to open, but I'm not sure how to exactly implement that.
What type does Windows pass to a program whenever we open a file? String?
Once my first question is fixed, is there anything special I would need to do to associate my program to image files (when making .exe file or installer)?
Include a java-web-start <association/> tag as a "hint to the JNLP client that it wishes to be registered with the operating system as the primary handler of certain extensions and a certain mime-type." Note that " the <offline-allowed/> element must also be included." A web server is not required and a platform-specific <shortcut/> is optional. The file to open will be a command line parameter.
Related
I am developing Media Player in JavaFx and now I want that when I right click on any media (.mp4) file and open with my JAR file that it will start playing. How to get this function work?
I am not a pro in java, but in most programming languages when we open with something, the path is sent as argument.
In java maybe the parameter String[] argsin main method, which is an array, will contain the path to the file you opened with. Then you can use it to open the file.
You can test it easily by printing the array args, and opening the mp4 file with .exe or .jar(not sure)
At end sorry for the confusion but I am at this time unable to test as i am away from any jvm.
If you want it in android then you have to further view intents-filters here
https://developer.android.com/guide/components/intents-filters
I am looking for a way, using java to find the default application for opening a certain extension. For example, I have Gimp set to open all .jpg files. So when I evaluate xyz.jpg I want to be able to find Gimp. I DO NOT want to open the file with the application I just want to know what it is.
I tried sifting through the registry and Gimp was not the default it was windows photo viewer even though the desktop recognizes it as Gimp.
I also tried using assoc and ftype from the command line and it also returned windows photo viewer. I assume this is because it is just looking at the registry.
Note: I do not want to change the default application in the registry I just want to know how I can find what the desktop finds as the default application for a certain extension.
Matt
I found the entries for user defined applications in the registry. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts.
I then loaded all these entries from the registry and grabbed what I needed.
I am using JNA with Java to find some properties about open windows on a Windows machine desktop. I am trying to find a way to get the file being accessed by an arbitrary windowed application. For instance, say I get information regarding the window of an open pdf document in adobe. I want to be able to get the filepath of the pdf document displayed in the window.
I know about the GetWindowModuleFileName() method, however this gets you the filepath of the executable of the application, i.e. 'javaw.exe'. If you have 'my.pdf' open in adobe, I'd like to get the filepath of this document, i.e. 'C:\...\my.pdf'.
I've done some searching around (on this site and others) and haven't found anything yet on this in particular.
thank you for your time, -Kevin
If you know the process ID, you can get the list of all files currently opened by the process using Handle utility. However, it depends if adobe reader continues to keep the file open or closes it after reading it completely.
I want to create my own file format for a particular kind of file. When someone downloads this file I want their system to know it should be opened with my application.
For example when I download a .doc file, my computer asks me whether I want to save the file or open it with Open Office. Similarly, If that .doc file is sitting on my desktop, and I double click it, it automatically opens with the correct application.
I believe this has to do with associating the file extension with the application in the context of the underlying OS.
Can any one point me to some good resources about how to do this in java?
Thanks.
Edit:
Sorry I want to clarify. Is there a way I can have my application associate the file type with itself when it is installed?
Edit:
found this...
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/jdic_assoc/
platform independent solution
This source shows how to make a file association in windows:
http://www.rgagnon.com/javadetails/java-0592.html
You will probably have to do it per installer that you make in each OS.
found this... http://java.sun.com/developer/technicalArticles/J2SE/Desktop/jdic_assoc/ platform independent solution
What I need is to instruct OS to open the file with the default program used for that file type. Exactly as if, i.e., that file was double-clicked by user under Windows.
The purpose is, i.e., "your PDF file was generated. Click here to open it".
In platform-independent way, if possible...
I dont know exact terms for what I want, so if someone could update tags, I'd most appreciate that ;)
You need the Desktop class, and the open() method in particular.
Launches the associated application to
open the file. If the specified file
is a directory, the file manager of
the current platform is launched to
open it.
Since Java 6, we have Desktop.open() for exactly that purpose.