Network listener Android

New java class: public class ConnectionChangeReceiver extends BroadcastReceiver { @Override public void onReceive( Context context, Intent intent ) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE ); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo( ConnectivityManager.TYPE_MOBILE ); if ( activeNetInfo != null ) { Toast.makeText( context, “Active Network Type : ” + activeNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show(); } … Read more

Comparison of Android networking libraries: OkHTTP, Retrofit, and Volley [closed]

I’m hoping someone can provide some concrete examples of best use cases for each. Use Retrofit if you are communicating with a Web service. Use the peer library Picasso if you are downloading images. Use OkHTTP if you need to do HTTP operations that lie outside of Retrofit/Picasso. Volley roughly competes with Retrofit + Picasso. … Read more

Android check internet connection [duplicate]

This method checks whether mobile is connected to internet and returns true if connected: private boolean isNetworkConnected() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected(); } in manifest, <uses-permission android:name=”android.permission.ACCESS_WIFI_STATE” /> <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” /> Edit: This method actually checks if device is connected to internet(There is a possibility it’s connected to … Read more

Broadcast receiver for checking internet connection in android app

Answer to your first question: Your broadcast receiver is being called two times because You have added two <intent-filter> Change in network connection : <action android:name=”android.net.conn.CONNECTIVITY_CHANGE” /> Change in WiFi state: <action android:name=”android.net.wifi.WIFI_STATE_CHANGED” /> Just use one: <action android:name=”android.net.conn.CONNECTIVITY_CHANGE” />. It will respond to only one action instead of two. See here for more information. … Read more