start Ping - Android Network

Android examples for Network:Ping

Description

start Ping

Demo Code

//package com.java2s;

import android.util.Log;
import java.io.IOException;

public class Main {

    public static boolean startPing(String ip) {
        Log.e("Ping", "startPing...");
        boolean success = false;
        Process p = null;//from  ww  w.j av a 2 s .  co  m
        try {
            p = Runtime.getRuntime().exec("ping -c 3 -i 0.2 -W 100 " + ip);
            int status = p.waitFor();
            if (status == 0) {
                success = true;
            } else {
                success = false;
            }
        } catch (IOException e) {
            success = false;
        } catch (InterruptedException e) {
            success = false;
        } finally {
            p.destroy();
        }

        return success;
    }
}

Related Tutorials