Skip to main content

Check Network code in Android studio

manifests

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>



public boolean isConnected(Context context){

    ConnectivityManager manager =(ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
if (info != null && info.isConnectedOrConnecting()){
android.net.NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if ((mobile != null && mobile.isConnectedOrConnecting()) || (wifi != null && wifi.isConnectedOrConnecting()))
return true;
else return false;

} else
return false;
}

Comments

Popular posts from this blog

Share Button code in android studio

if you want  to send any text from recyclerview to whatsapp then  use this code.   Intent intent = new Intent( Intent . ACTION_SEND ); intent .setType( "text/plane" ); intent .putExtra( Intent . EXTRA_TEXT , list .get( position ).getText()); context .startActivity( intent ); if u want to send app link then use this code Toast . makeText (getContext(), "Thanks for sharing" , Toast . LENGTH_SHORT ).show(); Intent sendIntent = new Intent(); sendIntent .setAction( Intent . ACTION_SEND ); sendIntent .putExtra( Intent . EXTRA_TEXT , "https://play.google.com/store/apps/details?id=com.ramsagar.quizzer" ); sendIntent .setType( "text/plain" ); Intent shareIntent = Intent . createChooser ( sendIntent , "Share Music world App" ); startActivity( shareIntent );

Toolbar code in Android Studio

XML code : < androidx.appcompat.widget.Toolbar android :id ="@+id/toolBar" android :layout_width ="match_parent" android :layout_height ="?attr/actionBarSize" android :background ="@color/colorPrimary" android :theme ="@style/ThemeOverlay.AppCompat.Dark" />   java code: Toolbar toolbar = findViewById( toolBar ); setSupportActionBar( toolbar ); getSupportActionBar().setTitle( "Attitude" ); getSupportActionBar().setDisplayHomeAsUpEnabled( true );