QtAndroid 名称空间

The QtAndroid namespace provides miscellaneous functions to aid Android development. 更多...

头: #include <QtAndroid>
qmake: QT += androidextras
Since: Qt 5.3

    类型

    enum BindFlag { None, AutoCreate, DebugUnbind, NotForeground, ..., ExternalService }
    flags BindFlags
    enum PermissionResult { Granted, Denied }
    typedef PermissionResultCallback
    typedef PermissionResultMap
    typedef Runnable

    函数

    QAndroidJniObject androidActivity ()
    QAndroidJniObject androidContext ()
    int androidSdkVersion ()
    QAndroidJniObject androidService ()
    bool bindService (const QAndroidIntent & serviceIntent , const QAndroidServiceConnection & serviceConnection , QtAndroid::BindFlags flags = ...)
    QtAndroid::PermissionResult checkPermission (const QString & permission )
    void hideSplashScreen ()
    void hideSplashScreen (int duration )
    void requestPermissions (const QStringList & permissions , const QtAndroid::PermissionResultCallback & callbackFunc )
    QtAndroid::PermissionResultMap requestPermissionsSync (const QStringList & permissions , int timeoutMs = INT_MAX)
    void runOnAndroidThread (const QtAndroid::Runnable & runnable )
    void runOnAndroidThreadSync (const QtAndroid::Runnable & runnable , int timeoutMs = INT_MAX)
    bool shouldShowRequestPermissionRationale (const QString & permission )
    void startActivity (const QAndroidJniObject & intent , int receiverRequestCode , QAndroidActivityResultReceiver * resultReceiver = nullptr)
    void startIntentSender (const QAndroidJniObject & intentSender , int receiverRequestCode , QAndroidActivityResultReceiver * resultReceiver = nullptr)

    详细描述

    The QtAndroid namespace provides miscellaneous functions to aid Android development.

    类型文档编制

    enum QtAndroid:: BindFlag
    flags QtAndroid:: BindFlags

    此枚举用于 QtAndroid::bindService to describe the mode in which the binding is performed.

    常量 描述
    QtAndroid::None 0x00000000 没有选项。
    QtAndroid::AutoCreate 0x00000001 Automatically creates the service as long as the binding exist. See BIND_AUTO_CREATE 文档编制了解更多细节。
    QtAndroid::DebugUnbind 0x00000002 Include debugging help for mismatched calls to unbind. See BIND_DEBUG_UNBIND 文档编制了解更多细节。
    QtAndroid::NotForeground 0x00000004 Don't allow this binding to raise the target service's process to the foreground scheduling priority. See BIND_NOT_FOREGROUND 文档编制了解更多细节。
    QtAndroid::AboveClient 0x00000008 Indicates that the client application binding to this service considers the service to be more important than the app itself. See BIND_ABOVE_CLIENT 文档编制了解更多细节。
    QtAndroid::AllowOomManagement 0x00000010 Allow the process hosting the bound service to go through its normal memory management. See BIND_ALLOW_OOM_MANAGEMENT 文档编制了解更多细节。
    QtAndroid::WaivePriority 0x00000020 Don't impact the scheduling or memory management priority of the target service's hosting process. See BIND_WAIVE_PRIORITY 文档编制了解更多细节。
    QtAndroid::Important 0x00000040 This service is assigned a higher priority so that it is available to the client when needed. See BIND_IMPORTANT 文档编制了解更多细节。
    QtAndroid::AdjustWithActivity 0x00000080 If binding from an activity, allow the target service's process importance to be raised based on whether the activity is visible to the user. See BIND_ADJUST_WITH_ACTIVITY 文档编制了解更多细节。
    QtAndroid::ExternalService -2147483648 The service being bound is an isolated, external service. See BIND_EXTERNAL_SERVICE 文档编制了解更多细节。

    该枚举在 Qt 5.10 引入或被修改。

    The BindFlags type is a typedef for QFlags <BindFlag>。它存储 BindFlag 值的 OR 组合。

    enum QtAndroid:: PermissionResult

    此枚举用于描述权限状态。

    常量 描述
    QtAndroid::Granted 0 权限被授予。
    QtAndroid::Denied 1 权限被拒。

    该枚举在 Qt 5.10 引入或被修改。

    typedef QtAndroid:: PermissionResultCallback

    Synonym for std::function<void(const PermissionResultMap &)>.

    typedef QtAndroid:: PermissionResultMap

    同义词 QHash < QString , PermissionResult >.

    typedef QtAndroid:: Runnable

    同义词 std::function<void()>。

    函数文档编制

    QAndroidJniObject QtAndroid:: androidActivity ()

    Returns a handle to this application's main Activity

    该函数在 Qt 5.3 引入。

    另请参阅 QAndroidJniObject , androidService (),和 androidContext ().

    QAndroidJniObject QtAndroid:: androidContext ()

    Returns a handle to this application's main Context. Depending on the nature of the application the Context object is either the main Service or Activity object.

    该函数在 Qt 5.8 引入。

    另请参阅 QAndroidJniObject , androidActivity (),和 androidService ().

    int QtAndroid:: androidSdkVersion ()

    返回 Android SDK 版本。这又称为 API 级别。

    该函数在 Qt 5.3 引入。

    QAndroidJniObject QtAndroid:: androidService ()

    Returns a handle to this application's main Service

    该函数在 Qt 5.7 引入。

    另请参阅 QAndroidJniObject , androidActivity (),和 androidContext ().

    bool QtAndroid:: bindService (const QAndroidIntent & serviceIntent , const QAndroidServiceConnection & serviceConnection , QtAndroid::BindFlags flags = ...)

    Binds the service given by serviceIntent , serviceConnection and flags serviceIntent object identifies the service to connect to. The serviceConnection is a listener that receives the information as the service is started and stopped.

    返回 true 当成功时

    Android documentation 文档编制了解更多细节。

    该函数在 Qt 5.10 引入。

    另请参阅 QAndroidIntent , QAndroidServiceConnection ,和 BindFlag .

    QtAndroid::PermissionResult QtAndroid:: checkPermission (const QString & permission )

    Checks if the permission was granted or not. This function should be called every time when the application starts for needed permissions, as the users might disable them from Android Settings.

    该函数在 Qt 5.10 引入。

    void QtAndroid:: hideSplashScreen ()

    立即隐藏闪屏。

    该函数在 Qt 5.7 引入。

    void QtAndroid:: hideSplashScreen ( int duration )

    Hides the splash screen, fading it for duration 毫秒。

    该函数在 Qt 5.10 引入。

    void QtAndroid:: requestPermissions (const QStringList & permissions , const QtAndroid::PermissionResultCallback & callbackFunc )

    Asynchronously requests permissions to be granted to this application, callbackFunc will be called with the results.

    该函数在 Qt 5.10 引入。

    QtAndroid::PermissionResultMap QtAndroid:: requestPermissionsSync (const QStringList & permissions , int timeoutMs = INT_MAX)

    Synchronously requests permissions to be granted to this application, waits timeoutMs to complete.

    该函数在 Qt 5.10 引入。

    void QtAndroid:: runOnAndroidThread (const QtAndroid::Runnable & runnable )

    Posts the given runnable on the android thread. The runnable will be queued and executed on the Android UI thread, unless it called on the Android UI thread, in which case the runnable will be executed immediately.

    This function is useful to set asynchronously properties of objects that must be set on on Android UI thread.

    该函数在 Qt 5.7 引入。

    void QtAndroid:: runOnAndroidThreadSync (const QtAndroid::Runnable & runnable , int timeoutMs = INT_MAX)

    Posts the runnable on the Android UI thread and waits until the runnable is executed, or until timeoutMs has passed

    This function is useful to create objects, or get properties on Android UI thread:

    QAndroidJniObject javaControl;
    QtAndroid::runOnAndroidThreadSync([&javaControl](){
        // create our Java control on Android UI thread.
        javaControl = QAndroidJniObject("android/webkit/WebView",
                                                    "(Landroid/content/Context;)V",
                                                    QtAndroid::androidActivity().object<jobject>());
        javaControl.callMethod<void>("setWebViewClient",
                                       "(Landroid/webkit/WebViewClient;)V",
                                       QAndroidJniObject("android/webkit/WebViewClient").object());
    });
    // Continue the execution normally
    qDebug() << javaControl.isValid();
    					

    该函数在 Qt 5.7 引入。

    bool QtAndroid:: shouldShowRequestPermissionRationale (const QString & permission )

    返回 true if you should show UI with a rationale for requesting a permission .

    该函数在 Qt 5.10 引入。

    void QtAndroid:: startActivity (const QAndroidJniObject & intent , int receiverRequestCode , QAndroidActivityResultReceiver * resultReceiver = nullptr)

    Starts the activity given by intent and provides the result asynchronously through the resultReceiver if this is non-null.

    resultReceiver 为 null,那么 startActivity() method in the androidActivity() will be called. Otherwise startActivityForResult() will be called.

    The receiverRequestCode is a request code unique to the resultReceiver , and will be returned along with the result, making it possible to use the same receiver for more than one intent.

    该函数在 Qt 5.3 引入。

    void QtAndroid:: startIntentSender (const QAndroidJniObject & intentSender , int receiverRequestCode , QAndroidActivityResultReceiver * resultReceiver = nullptr)

    Starts the activity given by intentSender and provides the result asynchronously through the resultReceiver if this is non-null.

    resultReceiver 为 null,那么 startIntentSender() method in the androidActivity() will be called. Otherwise startIntentSenderForResult() will be called.

    The receiverRequestCode is a request code unique to the resultReceiver , and will be returned along with the result, making it possible to use the same receiver for more than one intent.

    该函数在 Qt 5.3 引入。