How to sub-class the Google-Cloud-Messaging API in Qt



  • I have been following the docs for implementing the GCM service from Google. I have referenced the library through the command line tool from Android and i have created the AndroidManifest.xml file. So now I have gotten to the point where i need to implement the library into my code in Qt using c++.

    But looking at these docs I get a little confused: https://developer.android.com/google/gcm/client.html

    I don't know how import the library so i can use it. Do i need some kind of "#include" statement?

    Also, i am not sure what other information you guys will need in order to help me with this so I will explain the steps i took to get to this point.

    ========================================================

    1. Copy the library project at <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/ to the location where you maintain your Android app projects.

    I copied the /google-play-services_lib folder to my QtProjects folder where all my projects are.

    1. i used the command line tool to reference the google API using target 2:
      android update project --target 2 --path C:\Users\01222_000\QtProjects\app1 --library C:\Users\01222_000\QtProjects\google-play-services_lib

    2. i created the AndroidManifest.xml through Qt and added all the necesary lines per the docs

    <?xml version="1.0"?>
    <manifest package="org.qtproject.example" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
    	<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    	<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
        <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
    	
        <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --">
            <receiver
                android:name=".GcmBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND" >
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                    <category android:name="com.example.gcm" />
                </intent-filter>
            </receiver>
            <service android:name=".GcmIntentService" />
    	
            <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
                <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
                <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"/>
                <!-- 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"/>
                <!-- 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%% --"/>
                <!--  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 -->
    
                <!-- Splash screen -->
                <!--
                <meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/>
                -->
                <!-- Splash screen -->
    
                <!-- Background running -->
                <!-- Warning: changing this value to true may cause unexpected crashes if the
                              application still try to draw after
                              "applicationStateChanged(Qt::ApplicationSuspended)"
                              signal is sent! -->
                <meta-data android:name="android.app.background_running" android:value="false"/>
                <!-- Background running -->
            </activity>
        </application>
        <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>
        <supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
    
        <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
             Remove the comment if you do not require these default permissions. -->
        <!-- %%INSERT_PERMISSIONS -->
    
        <!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
             Remove the comment if you do not require these default features. -->
        <!-- %%INSERT_FEATURES -->
    
    </manifest>
    

    after all that I should be able to call the API as is described in the docs. But it doesn't work.
    I am probably missing something and I would be really glad if someone could point out to me what it is that I am missing.

    Sorry for the long post by the way and thanks in advance.


  • Lifetime Qt Champion

    Hi,

    AFAIK, that's a JAVA API so you would need to take a look at Qt's JNI helpers

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.