App API
Description
IDroidAppAPI App
Gives you access to manage apps on your device. With this interface you can install, uninstall, open, and close apps, as well as perform other app-related actions.
Most methods often need a packageName
parameter — this is the app's name, which helps to identify and manage the right app. To find an app's package name, you can use the Installed Apps tool.
This follows the same logic as the App Actions block for the Lite/Pro and Enterprise versions.
Properties
- Name of the current open app.
string Top { get; }
- Unique ID of the active Android process.
uint TopPid { get; }
Examples:
var app = instance.DroidInstance.App;
string top = app.Top;
uint TopPid = app.TopPid;
Methods
Open an app
void Open(string packageName)
Parameters:
string packageName // App name for this method to work.
Overload:
string activityName // Activity to launch for the app.
Example
//#1
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
app.Open(packageName); // Open the app
//#2
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var activity = ".MainActivity"; // Chrome's main activity (not a working example!)
app.Open(packageName, activity); // Open app with specific activity
Open an app with a specific URL
void OpenUrl(string url, string packageName)
Parameters:
string url // URL to open.
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var url = "http://ya.ru";
app.OpenUrl(url, packageName); // Open Chrome and go to ya.ru
Close a specific app
void Close(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
app.Close(packageName); // Close the app
Close all apps
void CloseAll()
Example
var app = instance.DroidInstance.App;
app.CloseAll(); // Close all apps
Clear app data
void Clean(string packageName)
This makes the app as fresh as after installation.
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
app.Clean(packageName); // Clear app data
Clear app cache
void CleanCache(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
app.CleanCache(packageName); // Clear app cache
Install an app using an APK
void InstallApk(string path)
Parameters:
string path // Path to the APK file.
Example
var app = instance.DroidInstance.App;
var pathApk = @"\chrome.apk"; // APK file path
app.InstallApk(pathApk); // Install the app
Check if an app is installed
bool IsInstalled(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var isApk = app.IsInstalled(packageName); // Check if app is installed
if (!isApk) // If not, install it
{
var pathApk = @"\chrome.apk"; // APK file path
app.InstallApk(pathApk); // Install the app
}
Uninstall an app
void Delete(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
app.Delete(packageName); // Uninstall the app
Get app's UID
string Uid(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var uid = app.Uid(packageName); // Get app UID
Get app data directory
string DataDir(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var directory = app.DataDir(packageName); // Get app data directory
Get a list of all apps on the device
string[] GetListPackages()
Example
var app = instance.DroidInstance.App;
var packages = app.GetListPackages(); // Get list of all installed apps
Get a list of all system apps on the device
string[] GetListSystemPackages()
Example
var app = instance.DroidInstance.App;
var packages = app.GetListSystemPackages(); // Get list of all system apps
Get a list of all user-installed apps on the device
string[] GetListUserPackages()
Example
var app = instance.DroidInstance.App;
var packages = app.GetListUserPackages(); // Get list of all user-installed apps
Get all notifications (in JSON format)
string GetAllNotifications()
Example
var app = instance.DroidInstance.App;
var json = app.GetAllNotifications(); // Get all notifications
project.Json.FromString(json); // Process JSON
Get notifications only for the selected app (in JSON format)
string GetAppNotifications(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var json = app.GetAppNotifications(packageName); // Get all notifications for the app
project.Json.FromString(json); // Process JSON
Clear all received notifications
void ClearAllNotifications()
Example
var app = instance.DroidInstance.App;
app.ClearAllNotifications(); // Clear all notifications
Clear notifications only for the selected app
void ClearAppNotifications(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
app.ClearAppNotifications(packageName); // Clear notifications for the app
Back up the data of a selected app
void BackupAppData(string packageName, string pathToBackup)
Parameters:
string packageName // App name for this method to work.
string pathToBackup // Path to save the backup.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var pathSave = @"/dir/bakups/name_bakup"; // Where to save the backup
app.BackupAppData(packageName, pathSave); // Make a backup
Restore app data from a backup
void RestoreAppData(string packageName, string pathToBackup)
Parameters:
string packageName // App name for this method to work.
string pathToBackup // Path to the backup.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var pathLoad = @"/dir/bakups/name_bakup"; // Backup storage path
app.RestoreAppData(packageName, pathLoad); // Load the backup
Get app cookies
string GetCookie(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var cookies = app.GetCookie(packageName); // Get app cookies
Get the path where app cookies are stored
string GetCookiePath(string packageName)
Parameters:
string packageName // App name for this method to work.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var pathCookie = app.GetCookiePath(packageName); // Get the cookie storage path
Delete an account
bool RemoveAccount(string name, string type)
Parameters:
string name // Account name.
string type // Account type.
For example, Yandex Go, Yandex Mail, and Yandex Music apps use a shared auth system. So, if you delete one of these apps, the other two can still access the account.
In these cases, you need to get the accounts from the app and force remove them.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var pathCookie = app.GetCookiePath(packageName); // Get the cookie storage path
Get all app accounts (in JSON format)
string GetAccounts(string packageName)
Parameters:
string packageName // App name for this method to work.
Overload:
string type // Account type.
Example
var app = instance.DroidInstance.App;
var packageName = "com.google.chrome"; // App name
var json = app.GetAccounts(packageName); // Get app accounts