C

QAndroidAppsUtils Class

Helper class wrapping the important functionalities to manage Android apps. More...

Header: #include <QAndroidAppsUtils>
CMake: find_package(Qt6 REQUIRED COMPONENTS AndroidAutomotiveBase)
target_link_libraries(mytarget PRIVATE Qt6::AndroidAutomotiveBase)
Inherits: QObject

Signals

void appInstalled(QtAndroidAppsUtils::QAppItem *appItem)
void appUninstalled(QString packageName)

Static Public Members

(since QtAndroidAutomotive 6.5) int appUid(const QString &packageName)
bool hasNotificationAccess(const QString &notificationListenerServiceName)
QtAndroidAppsUtils::QAppsListModel *installedAppsModel()
QAndroidAppsUtils *instance()
bool showAppInfo(const QString &packageName)
bool startActivityWithAction(const QString &action)
bool startApp(const QString &packageName)
(since QtAndroidAutomotive 6.5) bool startAppOnScreen(const QString &packageName, const QScreen *screen)
(since QtAndroidAutomotive 6.5) bool startAppOnScreen(const QString &packageName, int displayId)
bool uninstallApp(const QString &packageName)

Detailed Description

Member Function Documentation

[signal] void QAndroidAppsUtils::appInstalled(QtAndroidAppsUtils::QAppItem *appItem)

This signal is emitted when the corresponding appItem is installed.

[static, since QtAndroidAutomotive 6.5] int QAndroidAppsUtils::appUid(const QString &packageName)

Returns the UID for the package specified by packageName or -1 if the specified package cannot be found.

This function was introduced in QtAndroidAutomotive 6.5.

[signal] void QAndroidAppsUtils::appUninstalled(QString packageName)

This signal is emitted when the app with the corresponding packageName is uninstalled.

[static] bool QAndroidAppsUtils::hasNotificationAccess(const QString &notificationListenerServiceName)

Checks whether the Notification Listener Service, notificationListenerServiceName has notification access. Returns true if the access is granted, false otherwise.

The notificationListenerServiceName needs to be the full name of your notification listener service class that you defined in the AndroidManifest file. For more information, see Android: NotificationListenerService.

The notification access needs to be granted by the user from the notification access settings view. To open that view, you can do the following:

if (!QAndroidAppsUtils::hasNotificationAccess("com.example.mynotificationlistenerservice")) {
    QAndroidAppsUtils::startActivityWithAction(
                        "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
}

See also QAndroidAppsUtils::startActivityWithAction(const QString &action).

[static] QtAndroidAppsUtils::QAppsListModel *QAndroidAppsUtils::installedAppsModel()

Returns a model pointer (ownership transferred to the caller) based on QAbstractListModel for installed Android apps. The model manages a list containing app name, package name, and icon.

[static] QAndroidAppsUtils *QAndroidAppsUtils::instance()

Returns a pointer to the QAndroidAppsUtils instance.

[static] bool QAndroidAppsUtils::showAppInfo(const QString &packageName)

Shows the app info settings view for the package specified by packageName. Returns true if the app Activity is found and started, false if not found.

[static] bool QAndroidAppsUtils::startActivityWithAction(const QString &action)

Starts the activity associated to a given action. For more information, see Android: Building an Intent. Returns true if the app Activity is found and started, false otherwise.

For example, to open the Bluetooth settings view, you can use the following code:

void openBluetoothSettings()
{
    QAndroidAppsUtils::startActivityWithAction("android.settings.BLUETOOTH_SETTINGS");
}

[static] bool QAndroidAppsUtils::startApp(const QString &packageName)

Starts the app associated to a given package name, packageName. Returns true if the app Activity is found and stated, false if not found.

[static, since QtAndroidAutomotive 6.5] bool QAndroidAppsUtils::startAppOnScreen(const QString &packageName, const QScreen *screen)

Starts the app associated to a given packageName on screen identified by QScreen object.

Returns true if the app Activity is found and started, false if not found or the given screen is not valid.

This function was introduced in QtAndroidAutomotive 6.5.

[static, since QtAndroidAutomotive 6.5] bool QAndroidAppsUtils::startAppOnScreen(const QString &packageName, int displayId)

Starts the app associated to a given packageName on screen identified by displayId.

Returns true if the app Activity is found and started, false if not found or the given displayId is not valid.

This function was introduced in QtAndroidAutomotive 6.5.

[static] bool QAndroidAppsUtils::uninstallApp(const QString &packageName)

Requests the uninstall dialog for the app associated to a given package name, packageName. Returns true if the app Activity is found and started, false if not found.

Available under certain Qt licenses.
Find out more.