Apps

List the apps on a phone, check whether one is installed, open apps, links and Settings pages, find out which app is in front, and work with apps that guard their screens.

Most scripts start by opening an app. This guide covers the commands that deal with whole apps rather than the elements inside them.

List the apps on a phone

apps returns the installed apps with their package name, label, version and whether they are system apps. System apps are left out unless you ask for them.

droidline apps
droidline apps --system
for app in d.apps():
    print(app["package"], app["label"], app["version"])

everything = d.apps(system=True)
for (const app of await d.apps()) {
  console.log(app.package, app.label, app.version);
}

const everything = await d.apps(true);
foreach (var app in await d.AppsAsync())
    Console.WriteLine($"{app.Package} {app.Label} {app.Version}");

var everything = await d.AppsAsync(system: true);

This is also the quickest way to find an app's package name, which launch, in_app and notify_filter need. Search the list for the label you see on the home screen.

Check whether an app is installed

installed answers with the app's version name, or an empty string when the app is not on the phone.

droidline installed com.android.chrome
version = d.installed("com.android.chrome")
if not version:
    print("Chrome is not installed")
const version = await d.installed("com.android.chrome");
if (!version) console.log("Chrome is not installed");
var version = await d.InstalledAsync("com.android.chrome");
if (version == "") Console.WriteLine("Chrome is not installed");

Open an app

launch starts an app at its start screen and answers with how long the phone took. Pass an activity to open a specific screen, as long as the app lets other apps open it.

droidline launch com.android.settings
droidline launch com.example.shop com.example.shop.CartActivity
d.launch("com.android.settings")
d.launch("com.example.shop", "com.example.shop.CartActivity")
await d.launch("com.android.settings");
await d.launch("com.example.shop", "com.example.shop.CartActivity");
await d.LaunchAsync("com.android.settings");
await d.LaunchAsync("com.example.shop", "com.example.shop.CartActivity");

launch returns before the app has drawn its first screen. Follow it with wait for something you expect to see:

d.launch("dev.droidline.demo")
d.wait("text", "Sign in")

Screens an app keeps private cannot be opened directly. launch opens the start screen instead, and your script taps its way from there.

open_url opens a web address or an app's deep link. Pass a package to choose which app handles it. intent opens a screen by its action, which is how you reach a particular Settings page.

droidline open_url https://droidline.dev
droidline open_url "myapp://orders/42" com.example.shop
droidline intent android.settings.WIFI_SETTINGS
droidline intent android.settings.APPLICATION_DETAILS_SETTINGS package:com.android.chrome
d.open_url("https://droidline.dev")
d.open_url("myapp://orders/42", "com.example.shop")
d.intent("android.settings.WIFI_SETTINGS")
d.intent("android.settings.APPLICATION_DETAILS_SETTINGS", "package:com.android.chrome")
await d.openUrl("https://droidline.dev");
await d.openUrl("myapp://orders/42", "com.example.shop");
await d.intent("android.settings.WIFI_SETTINGS");
await d.intent("android.settings.APPLICATION_DETAILS_SETTINGS", "package:com.android.chrome");
await d.OpenUrlAsync("https://droidline.dev");
await d.OpenUrlAsync("myapp://orders/42", "com.example.shop");
await d.IntentAsync("android.settings.WIFI_SETTINGS");
await d.IntentAsync("android.settings.APPLICATION_DETAILS_SETTINGS", "package:com.android.chrome");

What to tap once a Settings page is open differs by phone maker and language. The recipes show it for Wi-Fi, mobile data, airplane mode, force stop and clearing data.

Find out which app is in front

current names the app and the screen (activity) in the foreground. in_app answers true or false for one app, which suits a check inside a loop.

droidline current
droidline in_app com.android.settings
print(d.current())   # {'package': 'com.android.settings', 'activity': '...'}
if not d.in_app("com.example.shop"):
    d.launch("com.example.shop")
console.log(await d.current());
if (!(await d.inApp("com.example.shop"))) await d.launch("com.example.shop");
var now = await d.CurrentAsync();
Console.WriteLine($"{now.Package} {now.Activity}");
if (!await d.InAppAsync("com.example.shop")) await d.LaunchAsync("com.example.shop");

Back, home and recent apps

droidline back
droidline home
droidline recents
d.back()
d.home()
d.recents()
await d.back();
await d.home();
await d.recents();
await d.BackAsync();
await d.HomeAsync();
await d.RecentsAsync();

Apps that guard their screens

Banking and payment apps often block screen capture, so screenshot returns a black picture while they are in front. Their buttons and labels usually still appear in dump, so finding and tapping elements by text, ID or description keeps working. Fingerprint, face and pattern checks are for a person to complete on the phone.

Clear an app's data

clear_data wipes an app's data in one command, but only in device owner mode. Without it, the recipes show how to do it through Settings.