Again stuck on the same problem.
I have found around that we can set static system settings like this:
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_USE_STATIC_IP, "1"); // to define it use static ip's
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_IP,"192.168.1.15");
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_NETMASK,"255.255.255.0");
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS1,"192.168.1.1");
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_GATEWAY,"192.168.1.1");
But No Success!
I don't understand that when to set these settings?
Should I do it before the wifi configuration creation or after saving the wifi configuration or even before activating it or after it?
However, I have tried the all possible cases from my side and when I check Android WiFi settings, I see it's still on DHCP.
A previous question i.e. How to configue a static IP address, netmask, gateway programmatically on Android 3.x or 4.x has completely ruined my android device and now it can't switch
ON its WiFi anymore.
I also tried static IP on my HTC phone and no success, its always in DHCP mode!
Do I need to call a "reconnect" command? If yes, then in which way?
I think you it should look like:
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_STATIC_IP,"192.168.1.15");
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_STATIC_DNS1, "192.168.1.1");
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_STATIC_GATEWAY, "192.168.1.1");
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_STATIC_NETMASK, "255.255.255.0");
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_USE_STATIC_IP, "1");
And don't forget the manifest:
<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
Regarding the WiFi problem that your device had, you can try switching the WIFI on programmatically. This post might be helpful:
How to programmatically turn off WiFi on Android device?
After more than a year, I give up with setting a static IP (or DHCP, DNS, ...). Simply it's not possible, or, better, it's not allowed (from an arbitrary application).
Someone says:
"You could use NDK - this gives you low-level access to Linux under Android. Warning: don't expect this to be documented or supported. They might even ban you from Android Market (I know I would)"
For those who want to have some expriences with NDK, here is the a link:
http://developer.android.com/tools/sdk/ndk/index.html
Good luck, and give some feedback if you find something interesting!
Related
I have a local device (on my wifi network) that can be accessed using a web browser. However, it regularly changes its IP (it is not fixed, and, unfortunately, can't be).
How could I write a java code, for a small android app using a webview, that could scan my network and find the device's IP, quickly and easily ? Connecting to my router everytime this happens is a real pain...
I'm trying to find the X in the following URL : 192.168.1.X:4600/wui
At least, I think the port (4600) and /wui part should help narrowing the search.
Any ideas ? I am completely lost there, this is way above what I can do with android studio.
Thanks ! :-)
is there a possibility to get USB mass storage information like the serial of an USB device in Java on Windows?
I tried to achieve that with USB4Java (low and high-level API) and it works, but the problem is that I have to install a customized driver to get access to the information from my Java app (described in the FAQ at http://usb4java.org/). When that special driver (created with Zadig) is installed I don't have any further access to the device from the Windows explorer (just from my Java app).
I would like to detect when a new USB device is attached and if it was attached, I would like to get some information like the serial number of the device, the device name, the drive letter that was assigned etc.
That app should be used by other users and I couldn't force them to create a customized driver for each device ...
Do you have any hints how to achieve that?
Thanks.
Edit: Is it possible to get the usb-port of a connected device with Java-built-in methods?
I've tried sth with FileSystemView.getFileSystemView().getSystemDisplayName() but there are no such options. Is there another possibility to get vendor id's or sth. similiar with Java?
Or is it possible to get the drive letter with USB4Java?
Thanks.
I want to write 2 Device Communication Servers for use with OpenGTS (Enterprise). Devices are Teltonika FM4200 and WirlessLinks Piccolo STX. can u give me a some tutorial or something useful. I still don't have idea on it.
Instead of DCS you can use Traccar server which already supports FM4200, the second device might already be supported as well, I just need some message examples to verify that. Configuration file to integrate two systems can be found here.
I updated to Android 3.2 and now when I call WifiManager.setWifiEnabled I get an error in the log saying WRITE_SECURE_SETTINGS permission needed.
Is this something that has changed with 3.2?
(Is this change documented somewhere?)
I would like to be able to disable Wifi from my app (most of the time) as its not needed and will only use more battery than necessary.
Is there a way to do disable Wifi from 3.2 onwards?
Regards
Jerry
WiFi power management is a system-wide setting and not the responsibility of your application. As long as you don't grab an explicit WifiLock or power-hungry WakeLock (such as FULL_WAKE_LOCK), then Android will respect the users power management choices and so should you.
If you still want to turn WiFi on and off, you need to make sure you have the CHANGE_WIFI_STATE permission.
I'm not sure why the log mentions WRITE_SECURE_SETTINGS, but unless you are explicitly catching an exception thrown by setWifiEnabled that complains about it, then the message isn't for you.
I'm trying to instantiate an URL object (in Java) with the address: http://www.cornellrams.com/rss.php. It gives me an UnknownHostException. The site is live and well, but I can't access the feed. Any ideas why it doesn't like me? This is on Android. I do have the internet permission in the manifest.
May be firewall is blocking network connection for the emulator. You need to set /allow emulator to use network connection and also set network connection sharing.
Double check the url ... chances are there's a typo in it somewhere. If not then DNS issue, but you can access the web browser ... so unlikely if you can browse.
Ensure you are using the correct protocol i.e http/https depending on whether you are using ssl
I often get issues with the wifi on my samsung gadgets. not sure what it is perhaps a request gets stuck so I'm forced to turn wifi off then back on again ... it happens a lot (especially with twitter app).
Also make sure that your timeout's are generous especially if using 3g rather than wifi.
I faced same problem once with my emulator. Restarting the emulator helped (maybe also with cleaning build).