• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Send data only when connected to WiFi?

I am trying to conduct a bit of research before starting to develop an android application I am planning. I want the application to exhibit the following behavior:


  1. If connected to WiFi, send and receive messages to remote server
  2. Else If not connected to WiFi, do not send any messages. Display error message.

I am trying to create an ethical application so users will not be charged when they become disconnected from WiFi without them noticing. If you could please point me towards any existing source/documentation on how to do this I would be grateful.
 
Hi
Here is the codelet which you could use to check is your device connected to any Wifi.

Code:
		ConnectivityManager conMgr = (ConnectivityManager) getApplicationContext()
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = conMgr
				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

		boolean isConnected = netInfo.isConnected();


-
 
  • Like
Reactions: Longshorts
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones