我的ping android应用无法连接到外部网络

时间:2019-06-26 16:29:34

标签: java android ping

基本上,我正在尝试在Ping应用上创建。但是当我运行此应用程序时,我的应用程序无法ping通所需的网络

未知主机ping www.google.com

我已对清单文件进行了更改,以寻求Internet许可

另外,当我将程序作为简单的Java类运行时,它运行得很好

private void ping(String s) {
        String str = "";
        int count = 0;
        try {

            Process process = null;

            if (Build.VERSION.SDK_INT <= 16) {
                // shiny APIS
                process = Runtime.getRuntime().exec(
                        "/system/bin/ping -w 1 -c 1 " + s);


            } else {

                process = new ProcessBuilder()
                        .command("/system/bin/ping", s)
                        .redirectErrorStream(true)
                        .start();

            }


            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    process.getInputStream()));

            StringBuffer output = new StringBuffer();
            String temp;
            while ((temp = reader.readLine()) != null)//.read(buffer)) > 0)
            {
                output.append(temp);
                count++;
            }
            reader.close();
            if(count > 0)
                str = output.toString();

            process.destroy();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Log.i("PING Count", ""+count);
        Log.i("PING String", str);
        }

我该如何运行?

0 个答案:

没有答案