S
S
SibVector2016-11-22 22:53:03
Android
SibVector, 2016-11-22 22:53:03

How to create a LiveWallpaper for Android in Qt?

How to create live wallpapers for android in QtQuick? Since version 5.7 Qt supports services, but these services are simple background applications. I shoveled the file Qt5.7.0\5.7\android_armv7\src\android\java\src\org\qtproject\qt5\android\bindings\QtService.java as best I could, something like this came out:

QtWallpaperService.java
public class QtWallpaperService extends WallpaperService {
/* тут все скопировано из QtService, но вместо onCreate() -> onCreateEngine() */
    @Override
    public Engine onCreateEngine() {
        Toast.makeText(getApplicationContext(), "onCreateEngine()", Toast.LENGTH_LONG).show(); // ok
        return new QtWallpaperEngine(m_loader);
    }

    private class QtWallpaperEngine extends Engine {
        private boolean mVisible = false;
        private final Handler mHandler = new Handler();
  private QtWallpaperServiceLoader m_loader;

        private final Runnable mUpdateDisplay = new Runnable() {
            public void run() {
                 Toast.makeText(getApplicationContext(), "run()", Toast.LENGTH_LONG).show(); // ничего
     m_loader.onCreate();
            }
        };
 
    private class QtWallpaperEngine extends Engine {
        private boolean mVisible = false;
        private final Handler mHandler = new Handler();
        private QtWallpaperServiceLoader m_loader;

        private final Runnable mUpdateDisplay = new Runnable() {
            public void run() {
            Toast.makeText(getApplicationContext(), "run()", Toast.LENGTH_LONG).show(); // ничего
                m_loader.onCreate();
            }
        };
 
        public QtWallpaperEngine(QtWallpaperServiceLoader loader) {
            super();
            Toast.makeText(getApplicationContext(), "QtWallpaperEngine()", Toast.LENGTH_LONG).show(); // ok
            m_loader = loader;
        }
 
        private void draw() {
            Toast.makeText(getApplicationContext(), "draw()", Toast.LENGTH_LONG).show(); // ничего (ну оно и понятно)
            m_loader.onCreate();
        }
 
        @Override
        public void onVisibilityChanged(boolean visible) {
            Toast.makeText(getApplicationContext(), "onVisibilityChanged: " + visible, Toast.LENGTH_LONG).show(); // ok onVisibilityChanged: true
            m_loader.onCreate();
        }
 
        @Override
        public void onSurfaceChanged(SurfaceHolder holder,
                    int format, int width, int height) {
        }
 
        @Override
        public void onSurfaceDestroyed(SurfaceHolder holder) {
            
        }
 
        @Override
        public void onDestroy() {
            
        }
    }
}


Also added corrections to the manifest:
AndroidManifest.xml
<!--                                                            ФИНТ vvvvvvvvvvvvvvvvvvvvvvvv -->
    <service android:process=":qt" android:name="org.qtproject.qt5.android.bindings.QtWallpaperService"
            android:enabled="true"
            android:label="Wallpaper Example"
            android:permission="android.permission.BIND_WALLPAPER">
        <!-- android:process=":qt" is needed to force the service to run on a separate process than the Activity -->

            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" >
                </action>
            </intent-filter>

            <meta-data
                android:name="android.service.wallpaper" android:value="-- %%INSERT_APP_LIB_NAME%% --"
                android:resource="@xml/mywallpaper" >
            </meta-data>

            <!-- Ministro -->
            <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
            <meta-data android:name="android.app.repository" android:value="default"/>
            <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
            <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
            <!-- Ministro -->

            <!-- Deploy Qt libs as part of package -->
            <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
            <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
            <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
            <!-- Deploy Qt libs as part of package -->

            <!-- Run with local libs -->
            <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
            <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
            <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
            <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
            <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
            <!-- Run with local libs -->

            <!--  Messages maps -->
            <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
            <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
            <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
            <!--  Messages maps -->

            <meta-data android:name="android.app.background_running" android:value="true"/>
        </service>


Wallpapers appeared in the live wallpaper menu, when they are installed, several Toast messages pop up on the screen (I marked them with comments in the code) and that's it, the activity itself does not appear. I think this is because I have QtWallpaperServiceLoader.java as my m_loader , which is a copy of QtServiceLoader.java . The service is working, but there are no pictures. Does anyone have any suggestions on how to make this mess work?
ps I tried to apply the same scheme for QtActivity , but there I had to cut too much code from both QtActivity itself and QtActivityLoader ... in the end, even Toasts did not appear for me :[

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question