如何在Android背景中ping服务器

时间:2014-12-12 23:04:58

标签: android

目前我的应用程序设置是在加载活动时ping服务器,并且它正常工作,但在此过程中,应用程序在ping所有服务器时进入黑屏。我想让它成为所有服务器在后台ping,并且用户仍然可以操作应用程序。继承我的代码:

        Runtime runtime = Runtime.getRuntime();
        Process  mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 sfb.noip.me");
        int mExitValue = mIpAddrProcess.waitFor();
        Process  mIpAddrProcess2 = runtime.exec("/system/bin/ping -c 1 sg.lbsg.net");
        int mExitValue2 = mIpAddrProcess2.waitFor();
        Process  mIpAddrProcess3 = runtime.exec("/system/bin/ping -c 1 peepzcraft.zapto.org");
        int mExitValue3 = mIpAddrProcess3.waitFor();
        Process  mIpAddrProcess4 = runtime.exec("/system/bin/ping -c 1 71.226.128.188");
        int mExitValue4 = mIpAddrProcess4.waitFor();
        Process  mIpAddrProcess5 = runtime.exec("/system/bin/ping -c 1 playmcpe.com");
        int mExitValue5 = mIpAddrProcess5.waitFor();
        Process  mIpAddrProcess6 = runtime.exec("/system/bin/ping -c 1 survival.dgpocket.us");
        int mExitValue6 = mIpAddrProcess6.waitFor();
        Process  mIpAddrProcess7 = runtime.exec("/system/bin/ping -c 1 
        minecraft.blocksandgold.com");
        int mExitValue7 = mIpAddrProcess7.waitFor();
        Process  mIpAddrProcess8 = runtime.exec("/system/bin/ping -c 1 pe.cookie-build.com");
        int mExitValue8 = mIpAddrProcess8.waitFor();
        Process  mIpAddrProcess9 = runtime.exec("/system/bin/ping -c 1 96.8.119.195");
        int mExitValue9 = mIpAddrProcess9.waitFor();
        Process  mIpAddrProcess10 = runtime.exec("/system/bin/ping -c 1 Play.mcpe-ba.info");
        int mExitValue10 = mIpAddrProcess10.waitFor();
        Process  mIpAddrProcess11 = runtime.exec("/system/bin/ping -c 1 64.94.238.196");
        int mExitValue11 = mIpAddrProcess11.waitFor();
        Process  mIpAddrProcess12 = runtime.exec("/system/bin/ping -c 1 leet.cc");
        int mExitValue12 = mIpAddrProcess12.waitFor();
        Process  mIpAddrProcess13 = runtime.exec("/system/bin/ping -c 1 ru.24serv.pro");
        int mExitValue13 = mIpAddrProcess13.waitFor();
        if(mExitValue==0){

            text.setText("Server Status: Online");              
        }else{
            text.setText("Server Status: Offline");              
        }

0 个答案:

没有答案