Code example for NetworkInfo

Methods: getState

0
        ConnectivityManager manager = (ConnectivityManager)
            context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = manager.getActiveNetworkInfo();
        if (info == null)
            return false; 
        if (info.getState() != State.CONNECTED)
            return false; 
        return true; 
    } 
 
    /** Fetch the image specified by the given url */ 
    public static Bitmap fetchImage(URL url) throws IOException {
        InputStream is = null;
        try { 
            URLConnection conn = url.openConnection();
            conn.connect();
            is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is, 16384);
            try { 
                Bitmap bitmap = BitmapFactory.decodeStream(bis);
                return bitmap;