首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android如何获取进程Id

2012-07-08 
Android怎么获取进程Id下面是通过linux命令来获取进程ID的Process psProcess Runtime.getRuntime().exec

Android怎么获取进程Id
下面是通过linux命令来获取进程ID的
Process psProcess = Runtime.getRuntime().exec("sh");
DataOutputStream out = new DataOutputStream( psProcess.getOutputStream() );
InputStream is = psProcess.getInputStream();
out.writeBytes( "ps | grep 'vpnloader' | cut -c 10-14\n" );
out.writeBytes( "ps\n" );
out.flush();
try {
    psProcess.waitFor();
     } catch (InterruptedException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();}
 
if(is.read() != 0)
{
   byte firstByte = (byte)is.read(); 
   int available = is.available();
   byte[] characters = new byte[available + 1];
   characters[0] = firstByte;
   is.read( characters, 1, available );
   String re = new String( characters );

热点排行