Android connection to router - java

I am developing an android application and it requests connecting to a linksys router and i wrote a code on java and it is working but when i tried to transform it to an android application i face a timeout exception in this line
JenNetIPNetwork network = service.createNetwork(new InetSocketAddress("fd04:bd3:80e8:2:215:8d00:32:54ff", 1873));
and i am using an emulator.
So is the problem that i am using an emulator not an android device?
And if there is other solutions any suggestions ?

There is possibly 2 problems.
1) your immolator is not connected with router (its your computer.) so try to connect immolator to router or use real device.(this problem has major chance to generate this bug.)
&
2) All networking related stuff in android must be in other thread. try that out.
Try this hope your problem would be solve by this.
one more thing you have to add internet connectivity permission in xml.(if not then do as well)

Related

Java - How to ping local IPs to find device with web app?

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 ! :-)

Android DownloadManager doesn't work in some circumstances

I'm using DownloadManager (Android, Java) to download files over WI-Fi from a machine in the same LAN. It works flawlessly on most of the phones I tested, but it appears that on some devices the download just doesn't start when WAN cable (Internet) is unplugged from the router (!). Everything gets back to normal on these phones when I'll connect the Internet cable. Other phones download the files without issues no matter if the Internet is connected to the router or not. This is puzzling me for over a week. There are no clues in logcat (download just doesn't start without any error). It's very odd as the Internet shouldn't have anything to do with the downloads. Everything is happening in the LAN. Any suggestions are welcome.
You can set setAllowedNetworkTypes flag.
refer this -> https://developer.android.com/reference/android/app/DownloadManager.Request.html#setAllowedNetworkTypes(int)
As it finally turned out the Fetch library also introduces the same problem. What worked for me, in this case, was crafting my own downloader with AsyncTask and InputStream.

TCP connection between Android App and PC

I'm trying to create a TCP connection between my PC and Android smartphone to send text from the PC (Client) to the Android App (Server).
I found a tutorial which helped me with the code for the App which creates the server ( http://pastebin.com/z0xPSAvP ).
Now I'm struggling connecting my client with the server. The client is programmed with "AutoIt"
http://pastebin.com/tCW5bK9V
When I run the client the "could not connect to $socket" msg-box is displayed.
Could someone tell me what I'm doing wrong here?
Both devices are in the same Network (smartphone via WiFi and PC via LAN) and I checked for the smartphones IP in the smartphone settings.
First, try to access something like Google from your Android phone using its mobile browser. Maybe something still wrong with the network.
Then create a version of the server that could deliver simple HTTP response, visible from the Android mobile browser. Doing so with success eliminates firewalls and all client-related issues from the list of possible problems, making sure the server works and is accessible.
If it still does not work after you demonstrate connection between server and mobile browser, I would suggest to write the client in Java first using the this tutorial. You can try AutoIt and other more exotic approaches after you get anything working at all.

Android chat working on emulators with redir

I have read tons of this same advices about connecting two emulators using telnet. For example this one: Connecting 2 Emulator instances In Android
I've made all as it is said and nothing works. I have got server app on emulator 5554 and client app on emulator 5556. They are using ports 6000 server app and 5000 client app. What I want is to communicate when this two emulators are open - in both ways.
At the beginning server app shows her ip, and in client app user have to write this ip. That is whole configuration.
As in mentioned post was said I've written redir add tcp:5000:6000 but nothing works. Also when I write redir add tcp:6000:5000 nothing happen. Those apps don't hear each other. However if server is on other device than everything works fine.
Maybe it is stupid question but can someone guide me through this, because I don't know what am I doing wrong.

Why am I getting a UnknownHostException?

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).

Categories