I have a java application and two different wireless network connections (wifi) on my desktop.
This is a desktop application, not android.
One method of this applicaiton works well with wifi1, second method works well with wifi2.
So far in order to use different methods I have to change wifi settings on my desktop manually.
Is there any way I could change wifi connection setting from the application programmatically ?
Java is a High-Level, Platform-Independent programming language. Network settings, and how you control them will depend on your Operating System, and to my knowledge there is no simple way to expose this in Java.
'
Luckily, some platform-dependent code mixed with Java can help you achieve the result you're after.
The Java
See the Runtime.exec() method, which allows you access to the Windows Command Line or the Mac/Linux Terminal.
The Windows (Adjust for other OS'es)
Now that we have access to the Command Line, we have to run the proper, platform-specific command. See this tutorial for Windows.
Note that it is not a good idea to modify a user's network settings (or anything else external to your application) without their consent.
Related
I am writing an android SSH Client. I have a terminal object that controls the view and an SSH object to send commands to the server.
My problem is that the terminal displays in color during all sessions but when an ncurses application opens, (tmux for example), the terminal displays in black and white.
I was able to find this: http://invisible-island.net/ncurses/ncurses.faq.html#white_black
I am not really sure what that means. Can anyone guide me on more documentation on this, or if there are any open source Java clients that support this feature. I am not really sure how to fix this.
Ok, so you launched the application without the TERM environmental variable set appropriately, and that meant that during the initialization routines the remote operating system believed it wasn't talking to a terminal that could support colors.
Now that you have it set correctly, your colors work. Congratulations! However, setting it inside the application is going to be quite a trick. This is because it needs to be set before you application launches. Otherwise, when the application launches, the low level libraries you are linking into will query the "environment" to see what kind of terminal it has, which determines what kind of terminal codes will be emitted by your application.
This all happens before you app launches; so, effectively, you can't really do it from your application. However, the real solution is a bit more interesting.
SSH makes very few assumptions about the display capabilities of the remote machine. The best way to "fix" this is to have the SSH client set the terminal type according to the SSH client's capabilities. Check your ssh client configuration to see if you can pass in a "better" terminal type.
In fact, having the host operating system assume the client's capabilities will create issues; however, demanding that every ssh client be configured to hand off it's terminal capabilities properly can be logistically impossible. So, you may want to strike a compromise. On the ssh server machine, try dropping a "wrapper script" to launch the application with a color terminal script. It would read something like
#!/bin/sh
TERM=xterm-256color
export TERM
exec launch-app "$#"
and be saved as launch-app-color or something similar.
I am developing an OSX application for school where multiple users of the same mac will able to launch the program based on shared configuration (i.e. database connection info).
By design, the normal user without administrative privilege should not be allowed to modify the configuration.
Based on unix convention, I am storing the configuration file under /usr/shared/, but this caused another problem:
- Even when logged in as administrator, application will not able to write to the location above. Users will have to launch the application with elevated privilege (using sudo) if they need to make changes to the configuration file.
My question is, whether using "sudo" to write to restricted area is a common practice in mac osx ?
I would say that using "sudo" on a Mac is only common practice for certain types of users, such as network administrators and users who like to do more than just use standard applications.
I certainly would not expect students and teachers to be using the terminal and sudo.
When developing OSX apps, Apple provides the Authorization Services, from the security framework, for the app to be able to separate privileged features from standard ones and prompt users for their credentials when required.
You will have seen this in the System Preferences panes, where you see the padlock icon. Any application can call upon these services, though I'm not sure if it's possible with Java. This is Apple's recommended method of handling a problem such as this, in addition to factoring out privileged tasks to a separate application with a function they term 'SMJobBless'.
Interestingly, the domain of your question maps directly onto Apple's described scenario of using this system for "Simple, Self-Restricted Applications".
With that being said, if only yourself or other network administrators are going to be modifying the config file, then I'd recommend leaving out any features in the app for modifying it and doing it directly with sudo and a text editor such as vi, when required.
Definitely, unless you chmod its privilege with sudo(root)
Well what I am trying to do, in the long run, is to change some LAN properties when the an ethernet cable is connected to a computer.
I want to run my Java program each time a LAN network is detected. I found a couple questions as to how to do this in C++, but nothing related to Java, specifically. Would this just involve the way I distribute my final application? As in, I could use Jar2Exe Wizard to package my Java program as a Windows service and then just figure out how to run that at startup. But is there any way to do this within the Java program itself?
Don't know what your specific need is but you could try this. This shows how to run windows commands from inside java so you wont have to create an external batch file.
How to Execute Windows Commands Using Java - Change Network Settings
Also check out this answer which talks about retrieving network name in java. then you can combine both!
How to get the wifi network interface name in java
I want to facilate my client to run java program through UNIX command prompt using some shells. It'll look more effecient if they would be able to give input through some GUI. So it can be tested immedietely. I dont want prefer unix commands fro input.
Can somebody tell me how to run Java swing or applet programs in UNIX?
As Thompson mentioned, looking at Java Web Start could be a good idea.
Otherwise, if what you want is to execute, using a *NIX-like terminal, an application located on a remote host and have it rendered on your local display, then you need to do a few things:
you need a working X server on the local machine
you need to export the DISPLAY to the local machine (you can do this by setting up the DISPLAY environment variable on the remote system)
then you need to start your Java app from the command-line.
Hope this helps.
Here's an example of how to export your display over SSH.
Java programs use the X windows system (just like any other GUI on Unix). Assuming your X windows system is setup correctly, you should just open up a JFrame and do your GUI coding just like Windows.
Using the command prompt to launch a GUI is so last millennium. If you can distribute from a server, look into Java Web Start to provide the end-user with a simple and painless install.
Oh, and of course, follow Starkey's advice to throw a JFrame into the mix.
If you have an X-server installed locally, Putty can tunnel the X11-graphics generated by Linux Java back from the server to your local machine, and view it there.
If the above doesn't make sense to you, your next best bet is either running the Java code locally with Java Web Start (and code it to communicate back to the remote server) or run Servlets inside a Java Web Server running on the remote host.
In other words, GUI over a Putty connection is not something which is easily done.
I want to send AT commands in my Android application, but I could not find the right syntax. How can I do this?
The invokeOemRilRequestRaw() and invokeOemRilRequestStrings() methods which have implementations in a number of classes (RIL, PhoneProxy, PhoneBase, and some others) are what you need, but they are not available through the SDK and thus off-limits to us mere mortals.
There is a great review of this in the XDA forum thread:
How to talk to the Modem with AT commands.
That thread show you how to send AT commands (ATC) with a remote
terminal (USB connected to you PC), but it has not yet solved the
problem of how to use a local (phone) terminal to talk to the
phone Modem.
You need a terminal application/program to do any talking to the
modem (remember, its a 2-way communication). So that's why you need
a rooted device, since the root kit usually come with Busybox
(that includes a microcom terminal program). Otherwise you have to
write your own program.
AFAIK. You can disconnect incoming calls in many other and easier
ways than with AT commands.
Use syntax like this and let me know:
echo -e "AT+CFUN=?\r\n" > /dev/ttyUSB0