Check automatically in background if Wi-Fi network connection is enabled - java

I am working on an application that is going to need to communicate with electrical plugs. These electrical plugs will be inside a specific network called "EPlugs Network" (for example).
I need to check automatically and continously if the connection to this network is still enabled.
If a Wi-Fi network is available, I need to check if this is the good one. I suppose it will be enough to just catch the name of said network.
If it is not the good one or if no Wi-Fi connection is enabled, I will need to create a pop-up and ask the user to connect to this specific network. Otherwise, the application should not be able to continue working.
Is there a native way to check Wi-Fi connection's presence?
Thank you for your help.

Related

Is there a way to programatically detect if WiFi AP isolation is in place?

Is there a way to programatically detect if WiFi AP isolation (sometimes called client isolation, too) is in place?
Background: I am maintaining a smartphone app, which uses broadcasts to identify other devices running the same app on the local network. (So that the user can establish a local P2P connection.) I would like to detect if AP isolation is filtering the broadcasts, in order to display helpful
information to the user.

Turn off specific USB port programmatically

I use an hardware device that goes in standby after it is not used for several minutes.
The only way to reactivate it is to unplug it from the USB port and reconnect it.
So I would like to know if there is a way to turn off (and then turn on) that specific USB port.
Thanks in advance!

Identify which android app makes which connection

I have been trying to find a way within my android application to determine which app is requesting a connection to the internet (or more formally establishes a TCP connection). Here is an application which already does that.
The above app determines all connections independently without the need of rooting the phone and only with the "Full network access" permission which is magnificent.
I am currently developing with the help of this source, a proxy server on android and I can easily read the connections the phone establishes over the Internet.
How do I determine which application is actually requesting the specific TCP (http/https) connection?
I came in contact with Peter, a developer of the mentioned application and he was very kind to provide an answer regarding in discovering connections.
Here is his answer:
You can find the network information in the standard kernel proc files, like in any other Linux distribution:
/proc/[pid]/net/tcp
/proc/[pid]/net/tcp6
/proc/[pid]/net/udp
/proc/[pid]/net/udp6
/proc/[pid]/net/raw
/proc/[pid]/net/raw6
The [pid] is the process id of your app, but each file holds information about all network connections for the corresponding protocol.

Q: How does wifi AP providers (e.g Starbucks,McD) pushes out "Sign In to surf website" notifications to customers, and how to implement that in JAVA?

I have 2 parts to my question. First is just a general question and second is more into app development and coding.
How does Starbucks/Coffee Bean/McDonalds pushes out notification whenever we as customers connect to their WIFI AP? They will push out notifications like "Sign In to proceed using the internet" in the status bar, and then redirects us to their website before we can start using the internet.
I am trying to create an app that does just that by creating a personal hotspot(that will have internet access), and whenever customers are logged into my hotspot, they will receive that same notification. My intention is to just direct them to a 'sign in' page in their browser, and once they click sign in, they will again be directed to my personal website. After that, they are free to surf any websites they want to.
So is it possible to do just that? I only want the app to be installed in my phone, and not in my customers phone.
I'm deducing a lot of this, but I don't see how else it could work.
The wifi hotspots you are referring to are themselves little web servers, in addition to being participants in the world wide web. When a browser sends a URL out, it eventually gets to a web server (we won't go into the DNS system here), and the web server -- a machine listening on one or two ports, ready to accept a URL via socket and return something in response -- responds to it.
In the case you're talking about, the little wifi web server stores the URL sent and, regardless of what it is, sends back the "login to continue" page, and ensures that it is responded to. Once it is, then it does its normal thing with the original URL, which in this case means it sends it out to the internet cloud for interpretation like a normal wifi hotspot would.
As future URLs are sent, the wifi hotspot ensures that the login has occurred -- perhaps it just uses the URL of the machine as a key to information about when it logged in last, or a cookie, there are a couple of ways -- and if there is a current login session, then it again passes the URL out to the internet cloud.
In order to do this in Java on your phone, you would need control of the socket input/output of the hotspot; you would have to be able to read the input, determine whether the login had occurred, and only then either pass along the incoming URL or store it so the login could take place. I don't know how you would do that.
What you describe is a "captive portal" - all new users connecting through the hotspot will have their HTTP requests redirected to this portal. Once you register, your IP-address is known and the redirect no longer occurs.
How this works on mobile devices is typically that when you connect to a hotspot your phone will try to access a well known address and when the redirection occurs to a HTTP-AUTH response it will then open the captive portal as part of the setup process. For instance in the case of the iPhone apple will try to access 'phobos.apple.com' which is why you'll often see this in the pop-up when you are trying to access a "other" website on an non-authenticated access point.
As regards doing this in Java, I think you will have a few problems on your hands. Typically Java only provides network access at TCP/UDP layers and above. Now what you could do is have your application acting as a "proxy" such that it relays all network activity through it, but this would be a heavy load for your application. It also would not have the transparency of the type of solutions you would be used to. Your users may also have to be told to access your site directly.
Your typical captive portal has a few different actors involved and a number of different protocols beneath the application layer. The Access Point needs to "know" whether a user is authorised or not (and thus is redirected to the portal, or gets to access the wider internet); The portal needs to be able to notify the portal upon authentication; 802.1x is used for the initial handshaking; DHCP to assign the IP-address based on MAC address.

A connection between 2 applications

I would like to manage a connection between 2 applications, they will run on diffrent phones.
The purpose doesn't really matters let's say that it would be some kind of a chat.
How can I create this connection between the applications? I know how to do it on pc java programs using the socket and the serverSocket classes but I guess it's diffrent in here since the phone might change his ip when he moves between networks.
So how would you do that? how would you create a connection between 2 applications/phones
Given the scenario you described in your comment, using Push Notification i.e Google Cloud Messaging (GCM) might be sufficient.
So, when program B wants update from program A, it will ask the server to push a notification (via GCM) to program A. Note that program A will not connect to the server every x time to check for updates.
Another out-of-the-box solution is to use SMS if the communication is not so frequent and messages are short. Here I mean SMS that will be processed directly by your app (given it has certain attention word) and will not go to the inbox i.e. no SMS notification on the phone
Since the two phones will, as you note, have changing IP addresses, you'll probably need to use an intermediary.
The general design pattern here would be to have a server with a fixed IP or DNS address that relays messages between your two mobile devices. The simplest implementation would be a webserver, to which each phone would connect via HTTP(S) to transmit data or poll for updates.
There are a number of backend-as-a-service platforms that provide this type of functionality pre-built, and would likely suffice for something like a chat system. Check out Cloudmine and Parse.
If you need a low-latency or near-realtime connection, you could also consider implementing your own server that uses the Android C2DM (Cloud to Device Messaging) service.
See Android's Sample Bluetooth Chat App, It will give you an idea for how it can be achieved.

Categories

Resources