kill Process By Adb Shell - Android Android OS

Android examples for Android OS:Process

Description

kill Process By Adb Shell

Demo Code


//package com.java2s;

import java.io.IOException;
import java.io.BufferedReader;

import java.io.InputStreamReader;

public class Main {
    public static void killProcessByAdbShell(int pid) {
        String cmd = "adb shell kill -9 " + pid;
        System.out.println("-------> cmd=" + cmd);
        try {/*from   w w  w . jav  a 2s .  c o m*/
            java.lang.Process process = Runtime.getRuntime().exec(cmd);
            InputStreamReader inputStreamReader = new InputStreamReader(
                    process.getInputStream());
            BufferedReader bufferedReader = new BufferedReader(
                    inputStreamReader);
            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                System.out.println("----> exec shell:" + line);
            }
            bufferedReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials