안드로이드 어플로 IP 주소를 찾으면 있는지 없는지 모니터링하는 어플을 만들계획입니다.
하나의 소스를 구했는데
이것을 화면으로 출력하는 방법을 모르겠습니다.
public class MainActivity extends AppCompatActivity {
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
Runtime runTime = Runtime.getRuntime();
String host = "192.168.0.13";
String cmd = "ping -c 1 -W 10 " + host; //-c 1은 반복 횟수를 1번만 날린다는 뜻
Process proc = null;
try
{
proc = runTime.exec(cmd);
}
catch(
IOException ie
)
{
Log.d("runtime.exec()", ie.getMessage());
}
try
{
proc.waitFor();
}
catch(
InterruptedException ie
)
{
Log.d("proc.waitFor", ie.getMessage());
}
//여기서 반환되는 ping 테스트의 결과 값은 0, 1, 2 중 하나이다.
// 0 : 성공, 1 : fail, 2 : error이다.
int result = proc.exitValue();
if(result==0)
{
Log.d("ping test 결과", "네트워크 연결 상태 양호");
}
else
{
Log.d("ping test 결과", "연결되어 있지 않습니다.");
}
}