Android : Check Network Connection


private void checkNetworkConnection() {
    ConnectivityManager connMgr =
            (ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
    if (activeInfo != null && activeInfo.isConnected()) {
        wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
        mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
        if(wifiConnected) {
            //Log.i(TAG, getString(R.string.wifi_connection));       
            Toast.makeText(getActivity().getApplicationContext(),"wifi_connection",Toast.LENGTH_LONG).show();;
        } else if (mobileConnected){
          //  Log.i(TAG, getString(R.string.mobile_connection));          
            Toast.makeText(getActivity().getApplicationContext(),"mobile_connection",Toast.LENGTH_LONG).show();
        }
    } else {
        //Log.i(TAG, getString(R.string.no_wifi_or_mobile));       
         Toast.makeText(getActivity().getApplicationContext(),"no_wifi_or_mobile",Toast.LENGTH_LONG).show();
    }
}


মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

Github: Push an existing repository from the command line

Android : Enable/Disable wifi programmatically

Android : Firebase Cloud Messaging