Remote Device Internet Connectivity Status - Android - android

I am working on a Server-client mechanism in which my client is a mobile device running any version of android. I want to check through my server if the remote android client is connected to the internet and the internet is working on it. I know there is no straight forward approach in this kind of scenario.
Would making the android client ping my server after every 5 minutes would be the best solution ? Or there is any other more efficient way that I am not aware of.
Any help regarding this would be appreciated.

You can use Connectivity Manager as a broadcast that can give you the status of the connectivity.
So whenever you want to check from server about the connectivity of the internet, you can use that status value to know the internet connection status.
As mentioned in docs (connectivity-monitoring) -
The ConnectivityManager broadcasts the CONNECTIVITY_ACTION ("android.net.conn.CONNECTIVITY_CHANGE") action whenever the connectivity details have changed. You can register a broadcast receiver in your manifest to listen for these changes and resume (or suspend) your background updates accordingly.
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>

Related

Android service for listening for network connections

As the title says, I'm wondering if the there is some way in Android for listen to network connections. Something like using a service that is registered to handle the SMS messages that, for example, we can consume the SMS and broadcast or not that SMS.
The idea is that my app will sit on the background and be notified when some app makes a network connection. Based on some rules, my app can decide if this network connection will be denied or allowed.
As an example, suppose an app tries to connect to the Wireless network with SSID "netA". My app would be notified and if the rule is to deny this app on "netA" the calling app would not be able to connect to the network.
Any idea if this is possible?
Why don't you use a Broadcast recevier that listen for some events?.
It seems to me from your description that you don't need a Service, that is a android component that runs long time task, but something that listens to events.
Give a look here

Android : How to upload data/sync to server automatically when mobile gets internet

I am developing a form based app in which I wish to store the forms when I am in offline mode and online mode. When user will be offline it will automatically send the data to server whenever it will get internet connection.
I have implemented and tested my api but how to sync the data according to internet connectivity is going over my head. Can someone suggest proper solution.
Is it something related to syncadapter?
If I will use cloud ant i.e DBaaS for database , will it be a good choice for me?
Please forward me some code snippets
Thanks in advance
You could use Cloudant.
Start by using sync-android on the device to store the data locally.
Then you'll need to be able to detect the device's connectivity status. Use Android's ConnectivityManager to detect when the device is attached to wifi or the cell network using getNetworkInfo.
When your device is connected to wifi, start a replication to the Cloudant server.
You can check the link below for internet connection status .
Broadcast receiver for checking internet connection in android app
When you have a broadcast receiver that receive internet connection , start an intent for uploading data to server. For that purpose volley is a good library.
https://developer.android.com/training/volley/simple.html

Android - automatically start a service when joining a specific wifi network

I am trying to build an application/service that will execute some coding everytime I connect to a specific wifi network (to log into that network and then keep the connection active ). I do already have the code for the login part and it is working fine, but I don't really know how I can automatically run this code when I connect to a network.
Ideally, I would like to build a service that starts when I join a specific wifi network, keeps the connection active (like makes a request every 10 min to keep the connection active) and finally stops when I leave that network.
I know how to build the service and keep it active, but don't know how to start and stop it automatically when joining / leaving a wifi network. Any suggestions on how to do this is appreciated. If my approach is not correct and there is a better/simpler way to do that, please let me know
Regards,
Marcel
you need a broadcast receiver.
this broadcast receiver will receives broadcasts of Wifi connected and wifi disconnected actions and from there you can start and stop your service.
Implement a BroadcastReceiver listening for the scan results from WifiManager.startScan()
Have a look at Android Scan for Wifi networks

How to monitor internet connection loss in android service

I want to write an android service at is activated when the internet connection goes down, and displays another activity to user when that happens. I don't know how to start to write this service. Can any one give me an idea or better tutorial how to catch the connection down within Android service.
Thanks
When Internet connectivity changes, the system sends out a broadcast with an android.net.conn.CONNECTIVITY_CHANGE intent. You should be able to create a broadcast receiver that will be called whenever the device is connected or loses its connection.
You've to write a receiver for the connection changes.
You can look right here : Android, How to handle change in network (from GPRS to Wi-fi and vice-versa) while polling for data

Android: Using service, check if connection get broken

Iam connection to services trougth my app, I woul like to check if the connections gets broken, alert a message than.
Or is this taken carre of in android?
If not, How should I take care of it? is there a timer?
If you are connecting to built-in services of Android, for example Connection with GPRS, WIFI or MOBILE 3G connection, then you can register a Broadcast Receiver that will tell the user when the connection is lost.
But if you are connecting to your custom-made services, for example ABC Application, then you would have to make your own service, that will periodically (example every 15mins) will check the connectivity with ABC Application. Hope this helps.

Categories

Resources