Tag Archives: Code Snippet

How to check different Network status in Android?

By | May 5, 2012

This code snippet checks which of your networks are available in android. [java] package com.coderzheaven.pack; import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.os.Bundle; import android.widget.Toast; public class CheckConnectionsDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); checkAvailableConnection(); } void checkAvailableConnection() { ConnectivityManager connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final android.net.NetworkInfo mobile =… Read More »

Exception Handling – Divide by Zero – Java Example

By | June 25, 2011

Hi, Given below is a code snippet which will demonstrate an exception handling in Java with Divide by zero error. [java] public class MainClass { public static void main(String args[]) { int urAns, urDiv; try { urDiv = 0; urAns = 25 / urDiv; System.out.println("Do you really think this will print out? No! It won’t!"); } catch (ArithmeticException… Read More »