Android实现ping功能
Andriod实现ping功能,输入需要ping的地址、ping的数据包个数和大小、以及每隔多久ping一次,ping功能比较耗时,所以在开启的子线程中进行,然后把ping结果发送到主线程中更新Textview显示结果。对结果可以有两种操作,一是复制,二是保存到本地SD卡中,方便以后查看。
资源可以从http://download.csdn.net/detail/offerfinder/8903779免费下载,下面是效果图:
主界面:
结果:
对结果进行的操作:
下面看具体代码:
布局文件:
/PING测试/res/layout/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="IP地址"
android:textSize="18sp" />
<EditText
android:id="@+id/edit_ip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="www.baidu.com" />
<TextView
android:id="@+id/tv_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发送数据包的数目(个)"
android:textSize="18sp" />
<EditText
android:id="@+id/edit_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="4" />
<