这里的toPing压根就没有进去。 未解决
package com.example.graphserviceping;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.security.auth.login.LoginException;
public class MainActivity extends AppCompatActivity {
EditText editText;
Button button;
String ipString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.edt_iparr);
ipString = editText.getText().toString();
}
public void toPing(View view) {
Toast.makeText(MainActivity.this,"cccccccccccccccccccc",Toast.LENGTH_LONG);
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
Process p = Runtime.getRuntime().exec("ping -c 1 -w 1" + ipString);
InputStream inputStream = p.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer stringBuffer = new StringBuffer();
String content = " ";
// Toast.makeText(MainActivity.this,“bbbbbbbbbbbbbbb”,Toast.LENGTH_LONG);
while ((content = in.readLine()) != null) {
stringBuffer.append(content);
Toast.makeText(MainActivity.this,“aaaa”,Toast.LENGTH_LONG);
}
// Log.i(“tag”, content);
// editText.setText(content);
} catch (IOException e) {
e.printStackTrace();
}
}
};
Thread thread = new Thread(runnable);
thread.start();
}
}