def is_app_running(package_name): """Is an app with 'package_name' currently running on the device?""" p = subprocess.Popen([adb_path(), 'shell', 'ps'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = p.communicate()[0] return package_name in output
def stop_app(package_name): """Stop the app with 'package_name on the device.'""" cmd = [adb_path(), "shell", "am", "force-stop", package_name] subprocess.call(cmd)