C

QActivityView Class

A C++ wrapper for the ActivityView Java class. More...

Header: #include <QActivityView>
qmake: QT += androidactivityview
Since: Qt 6.3
Inherits: QObject

Public Types

enum class Status { NotInitialized, Ready, Starting, Started, RemovedExternally }

Public Functions

QActivityView(QObject *parent = nullptr)
virtual ~QActivityView()
QString activityClassName() const
QString activityPackageName() const
float cornerRadius() const
(since QtAndroidAutomotive 6.7) const QMatrix4x4 &currentFrameTextureTransformation() const
(since QtAndroidAutomotive 6.7) qint64 currentFrameTimestamp() const
(since QtAndroidAutomotive 6.7) void forwardInputEvent(const QJniObject &inputEvent)
QRect geometry() const
void initialize()
(since QtAndroidAutomotive 6.7) bool isNewFrameAvailable() const
bool isRestoreOnAppResumeEnabled() const
bool isVisible() const
void restore()
(since QtAndroidAutomotive 6.7) void sendKeyClick(int keyCode)
(since QtAndroidAutomotive 6.7) void sendTouchEvent(const QTouchEvent &touchEvent, const QTransform &transform = {})
void setActivityName(const QString &packageName, const QString &className = QString())
void setGeometry(const QRect &geometry)
void setRestoreOnAppResume(bool restore)
void setVisible(bool visible)
(since QtAndroidAutomotive 6.7) std::unique_ptr<QRhiTexture> startRendering(QRhi *rhi, int textureWidth, int textureHeight)
QActivityView::Status status() const
(since QtAndroidAutomotive 6.7) void stopRendering()
(since QtAndroidAutomotive 6.7) void updateCurrentFrame()

Signals

void statusChanged(QActivityView::Status status)

Detailed Description

QActivityView allows embedding and handling Android apps and activities.

Activity View Known issues and limitations

Since ActivityView needs special permissions and also relies on private Android APIs, apps that use it must be signed with a platform key.

Android 10

The Activity resolved by the provided packageName and className must have the resizeableActivity attribute set to true in order to be launched correctly as an embedded activity. Also, if the activity is not owned by the owner of this app, it must allow embedding. This rule also applies to activities launched from within embedded activities. Otherwise, new activities may not behave correctly, e.g. be launched in fullscreen.

Member Type Documentation

enum class QActivityView::Status

Indicates the status of the managed Activity.

ConstantValueDescription
QActivityView::Status::NotInitialized0The component instance is not yet initialized. Initialization is in progress and must complete before any activity can run. This process involves allocating the appropriate resources, such as creating a Surface. Initialization is done once for each instance of the ActivityView component.
QActivityView::Status::Ready1The component instance is initialized, but valid package/class names are not set. After setting a valid package/class name, the activity will be launched immediately.
QActivityView::Status::Starting2The activity defined by package/class names is currently being started.
QActivityView::Status::Started3The activity has been started.
QActivityView::Status::RemovedExternally (since Qt 6.4)4The activity has has been removed from this ActivityView. This happens whenever the app is active and the activity has been run somewhere else or closes. Second case is when the app is not active (suspended ,for example), restoreOnAppResume is set to false and the activity is run somewhere else or closes.

See also status() and statusChanged().

Member Function Documentation

[explicit] QActivityView::QActivityView(QObject *parent = nullptr)

Creates a wrapper for the ActivityView Java class and sets parent as the parent object.

[virtual noexcept] QActivityView::~QActivityView()

Destroys the wrapper object, releasing the underlying Java object of ActivityView class.

QString QActivityView::activityClassName() const

Returns the class name of the activity.

See also setActivityName().

QString QActivityView::activityPackageName() const

Returns the package name of the activity.

See also setActivityName().

float QActivityView::cornerRadius() const

Returns the corner radius of the managed Activity expressed in pixels.

[since QtAndroidAutomotive 6.7] const QMatrix4x4 &QActivityView::currentFrameTextureTransformation() const

Returns the transformation matrix that will be applied to the texture during rendering.

This function was introduced in QtAndroidAutomotive 6.7.

See also updateCurrentFrame().

[since QtAndroidAutomotive 6.7] qint64 QActivityView::currentFrameTimestamp() const

Returns the timestamp of the current frame.

This function was introduced in QtAndroidAutomotive 6.7.

See also updateCurrentFrame().

[since QtAndroidAutomotive 6.7] void QActivityView::forwardInputEvent(const QJniObject &inputEvent)

Forwards the inputEvent to the underlaying activity.

This function was introduced in QtAndroidAutomotive 6.7.

QRect QActivityView::geometry() const

Returns the position and size of the managed Activity expressed in the global coordinate system.

See also setGeometry().

void QActivityView::initialize()

Initializes underlying Java resources, such as creating a Surface. It requires setGeometry to be called first. Subsequent calls have no effect.

[since QtAndroidAutomotive 6.7] bool QActivityView::isNewFrameAvailable() const

Queries and returns true if a new frame is available to be rendered. Otherwise returns false.

This function was introduced in QtAndroidAutomotive 6.7.

See also updateCurrentFrame().

bool QActivityView::isRestoreOnAppResumeEnabled() const

Returns whether an activity lost during app's inactive state should be restored.

See also setRestoreOnAppResume().

bool QActivityView::isVisible() const

Returns whether the managed Activity is visible. By default this is true.

See also setVisible().

void QActivityView::restore()

Reloads the embedded activity if it was removed externally from the ActivityView.

[since QtAndroidAutomotive 6.7] void QActivityView::sendKeyClick(int keyCode)

Sends a key click with keyCode to the underlaying activity.

This function was introduced in QtAndroidAutomotive 6.7.

[since QtAndroidAutomotive 6.7] void QActivityView::sendTouchEvent(const QTouchEvent &touchEvent, const QTransform &transform = {})

Sends touchEvent to the running Android activity. It applies the optional transform to the touch coordinates.

This function was introduced in QtAndroidAutomotive 6.7.

void QActivityView::setActivityName(const QString &packageName, const QString &className = QString())

Sets the package name and the class name of the activity to be launched. The packageName must be specified using the full package name. The className is an optional argument specifying the name of a class inside of the application package. When the class name is not provided the default class is the one that is appropriate to launch a main activity in a package:

activityView.setActivityName("com.android.deskclock");

The class name can be specified using its full name:

activityView.setActivityName("com.android.deskclock",
                             "com.android.deskclock.settings.SettingsActivity);

However, if the first character in the className property value is a period, the packageName is prefixed to the className. The snippet above can be shortened to the following form:

activityView.setActivityName("com.android.deskclock",
                             ".settings.SettingsActivity);

If the component is initialized, the activity starts immediately. Otherwise, startup is postponed until initialization.

The Activity resolved by the provided packageName and className must meet certain criteria. Check out Known issues and limitations section for details.

See also activityPackageName(), activityClassName(), and initialize().

void QActivityView::setGeometry(const QRect &geometry)

Sets the position and size of the component on the screen. The x and y coordinates of geometry are in the global coordinate system. This first call to this method must be done before initialization in order to determine initial location and size of underlying resources. When invoked later, it changes the activity geometry immediately.

See also geometry().

void QActivityView::setRestoreOnAppResume(bool restore)

Turns on/off, depending on restore value, the possibility of restoring the embedded activity after it is lost during inactive state of the app. Restoring takes place when the app goes back to the active state.

See also isRestoreOnAppResumeEnabled().

void QActivityView::setVisible(bool visible)

Sets the visibility to the value of visible.

See also isVisible().

[since QtAndroidAutomotive 6.7] std::unique_ptr<QRhiTexture> QActivityView::startRendering(QRhi *rhi, int textureWidth, int textureHeight)

Starts rendering the activity by creating a QRhiTexture instance using the given rhi and textureWidth and textureHeight. Returns a unique pointer of the created QRhiTexture or nullptr in case of failure. The calling function takes the ownership of the returned value.

This function was introduced in QtAndroidAutomotive 6.7.

See also stopRendering().

QActivityView::Status QActivityView::status() const

Returns the current status of the activity.

See also statusChanged().

[signal] void QActivityView::statusChanged(QActivityView::Status status)

This signal is emitted when the status of ActivityView changes. The status indicates the new value of the status.

[since QtAndroidAutomotive 6.7] void QActivityView::stopRendering()

Stops rendering and detaches the underlaying texture that is managed by QRhiTexture. It is the user's responsibility to delete the QRhiTexture instance that has been previously returned by calling startRendering(), after calling this function.

This function was introduced in QtAndroidAutomotive 6.7.

See also stopRendering().

[since QtAndroidAutomotive 6.7] void QActivityView::updateCurrentFrame()

Updates the QRhiTexture returned by startRendering() with current available frame.

This function was introduced in QtAndroidAutomotive 6.7.

See also updateCurrentFrame(), currentFrameTimestamp(), and isNewFrameAvailable().

Available under certain Qt licenses.
Find out more.