Is there any way to change the system volume on Windows with Java or CMD programmatically?
I've found some command lines for Linux and Mac, but so far nothing for stupid Windows.
Take a look at a form post on oracles website https://forums.oracle.com/thread/2390172 you can see it is not possible from inside java using native libraries.
Quote from the oracle post: "Because Java is cross-platform, it cannot do platform-specific stuff like changing the volume or whatever you want to do to control the OS. You need to use the operating system's unique API layer to do it."
For command line I found this utility that seems to have what you are looking for http://www.nirsoft.net/utils/nircmd.html
If you don't want to rely on 3rd party executables you could either make your own exe or make a dll and look into using JNI.
Related
For some reasons I have to work under windows 10 OS with Android-Studio as IDE. My problem is that, exoplayer uses software and hardware decoders of Android-TV device to decode video streams.
Apparently, most of the Android-TV devices have no built-in decoder for decoding mpeg-2 sounds and therefore, the sound of the mpeg-2 streams are mute however, mpeg-2 videos are playing well. In order to solve such problems, I believe that I have to embed Ffmpeg extension into exoplayer. To do this, I followed the instruction of here under Windows PowerShell as recommended, but there are some problems.
First: What should be the value of HOST_PLATFORM variable for windows when using PowerShell?
Second: For unknown reasons I am receiving the following messages when executing Shell script "build_ffmpeg.sh".
What I receive when I execute shell script
Now, how can I embed ffmpeg extension for exoplayer (under windows 10 OS), enable it for decoding and solve these problems? My programming language is java. Thanks.
Note: Please tell me if you have any other (Other than embedding Ffmpeg into exoplayer) suggestions to solve my problem.
To build FFmpeg for ExoPlayer under Windows, you can use Git Bash for Windows to perform the building process.
All commands are almost the same (we'll get to the differences in a minute). Please note that NDK_PATH is the path of your NDK's folder (it's usually the version number, you can find it in default cases in YourAndroidSDK\ndk\yourNDKversion).
As for the differences, it's only for HOST_PLATFORM, you should use windows-x86_64, by inspecting the build_ffmpeg.sh, there is a line that says:
TOOLCHAIN_PREFIX="${NDK_PATH}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin"
The variable HOST_PLATFORM is only utilized to get the correct NDK tools for Windows. If you go and check the above path, you'll find a folder named windows-x86_64 under 'prebuilt'. That's what goes in HOST_PLATFORM.
If you get the NDK path correctly, HOST_PLATFORM correctly, FFMPEG_MODULE_PATH correctly, and last but not least the ENABLED_DECODERS, you should be able to build FFmpeg very easily.
If you don't want to go through setting the variables all over again, just edit the build_ffmpeg.sh file using Notepad, and edit the variable to make 'em be as you want without having to do it in the PowerShell terminal all over again.
I'm developing a JavaFX application for both Windows and Linux (Debian/Ubuntu distributions), currently on Linux Mint (I honestly don't have any experience with other distros than Mint). The application should be able to open folders with the system's file manager.
While on Windows I use this with no problems:
Desktop dt = Desktop.getDesktop();
dt.open(path);
This doesn't seem to work on Linux, so I thought of simply using Bash commands like:
ProcessBuilder builder = new ProcessBuilder("sh", "-c", "nemo " + path);
But this only works on Linux Mint Cinnamon, since KDE and other editions may come with different "default" file managers (like Dolphin or Nautilus).
Now is there a way, either programmatically with Java or with Bash, to get the associated file manager?
You need to find the default file manager.
You can use the xdg-mime command for that.
xdg-mime query default inode/directory return the default file manager.
Output if it's dolphin : dolphin.desktop
OR
xdg-open <directory> but it can start the wrong file manager sometimes.
See the documentation for more.
xdg-open <directory> has been deprecated
use 'gio open' instead. see source
you have to double think things... what is for you to open a folder ??? What does it mean? different operating systems (like windows, mac, or the like) have different file managers, so the mechanisms are subject to differences (mostly as they have evolved from previous environments, sharing nothing in common and without java in mind). Even there are operating systems with no file manager at all, as for example linux console applications don't assume a desktop is running at all and cannot call the file manager to open a window (where? no windows at all, only the black console screen) and show the files contained there.
Windows applications user the file Explorer to show folder contents and the communication with the explorer follows a path that doesn't share anything in common (while the mechanism is similar, anyway) with the one used in linux.
In linux you have the added problem that there are several (better said, many) desktop environments competing and doing things differently between each other.
The java support doesn't dig so deep in the desktop environment to allow for the task you face on in a desktop environment independent way.
Anyway, there are several file managers written in java that do the same and can be run in either environment (java, windows and the mac), so you can run other route, and use a common file manager for the task. And probably communicating with a program written in java is easier from your application.
I am looking for a way to mimic operating-system (Windows in specific) actions through Java. Preferably, the program should run in the background, but it is not a big deal if it does not. I got the background part covered thanks to this question. I was looking for the following specific features :
Maximizing/Minimizing the currently active window. (Can be any window, not just the Java application window.)
Closing the currently active window.
Open installed programs, and system utilities like the calculator, paint, etc. (I figured out this one from this question.)
Shutdown/Restart (This one's done too, thanks to the question here.)
So, my actual question is:
Is it possible to minimize/maximize or close an application window from a java program? (in Windows)
Example Scenario:
Firstly the java program is started, and it runs either as a background process or as a window. Bottom-line is that it should be able to accept triggers like maybe a keyboard shortcut or microphone input to trigger the action. After that suppose a Chrome window is opened and is currently active. Now on pressing the pre-defined shortcut, the Chrome window will minimize/maximize or close.
If the answer to the question is yes, I could use some pointers to start with my application. Thanks!
What you need is like an OS shell programming interface.
In Java side you will define a few interfaces.
Another Java layer will detect which OS is used and will return an implementation of interface: Windows, Linux, Macosx.
Some functionality you can have with simple bash command: in windows cmd, in linux .. to many. Eg shut down, launch MSPaint, Calculator.
Other functionality you can have it with windows API: you will need to write some JNI functions and call it. eg minimize, maximize. It is possible.
Edit:
I see there is no accepted answer, although it is answered properly.
Here is a C# code which does what you need in Java.
Now you need to migrate this code to Java:
In your java class declare a function:
private native maximizeOrMinimizeWindowWithName(String windowName, boolean maximize);
Compile -it
use Javah.exe - it will generate the necesary .h files
Use a C editor, configure environment, use the generated .h file.
-include windows api headers
-load user32.dll
- do more stuf..
compile your C code to .dll
put the your.dll into your app PATH environment variable. ( windows has the . in path, linux not)
-text, bugfix,
for more info you should see a basic JNI tutorials.
-upvote accept :)
This can be initiated from Java, but not actually implemented in Java. In other words, it will take a lot of platform-specfiic JNI library code to get it working.
Java will give you almost no benefit for your use case; you should avoid it altogether for this project.
You should look into Autohotkey. It's an system dedicated to simulate user programmaticly.
Using AH scripts you can easily access all open windows, installed programs and even control mouse and keyboard.
I have a program (java jar file) that I want to distribute on CDs. My friend told me that there are free/open-source CD installers available that automatically install your program onto the customer's computer.
Now I can't seem to find this on Google. So are there any CD installers that you would recommend that I can use (so I don't need to program one myself).
Outline:
My program consists of class files, sound files, source files (i'm open source) and images (packaged into a jar file).
I only need the installer to work for Windows computers.
I think IzPack does something like that.
You can look into Java WebStart which in Java 6 was enhanced to allow "launch-from-cd-and-install-to-harddrive" which mean that it can work as a very simple installer.
It requires a JVM already present. You can put the redistributable JRE on the cd too.
Launch4J is what I have used as my installer. It is really lightweight and has a nice GUI that makes things simple for the developer (one reason I chose not to use IzPack).
It makes things dead simple for both the developer and the user.
Your jar file is wrapped in a exe launcher.
If an up to date JRE is not detected, a bundled JRE is used or the user is prompted to download via java.com/download
Really, I couldn't have asked for anything simpler/better. Although you might get more functionality out of IzPack, if you want something dirt quick that can do everything the everyday developer needs, go for Launch4J.
P.S. Their splash screen option is a nice bonus :)
After running into numerous end problems, I finished the job with the use of Inno Setup.
Very quick and easy to use. Creates an installer similar to the ones you would see in popular programs. Gives you (and the user) the ability to create Desktop Shortcuts, QuickLaunch Icons and Startup folders. Allows you to add license information etc. Very simple and intuitive interface, I didn't have to read any documentation!
A big con: Only makes installers for windows. That met my requirements, but may not work for everyone.
First of all, I'm a java developer and I am currently working on a small application for Windows only.
In my application, I wish to do as dropbox or tortoise do : add an overlay icon in windows explorer to show the user some state of files managed by my application. (I want the icon of the file change depending on some data stored in the file)
Is it possible to do so in Java ? Do you have examples ?
If it is doable but not efficient, how would you do instead ?
Thanks in advance
Fluminis
It would be possible to do this via JNI - you would need to hook into the Windows registry and from there into the Explorer shell, probably into the various file classes held there.
However, unless you have at least some familiarity with C++ and the windows API, you are unlikely to be able to achieve this.
Java is not the ideal language for what you want to do.