Click using Parse on Qt5.5 for Android: NullPointerException on getCurrentInstallation

I am trying to use the parse.com push service with Qt5.5 on Android. When I try to call ParseInstallation.getCurrentInstallation (), I get the following error:

W/System.err( 9094): java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
W/System.err( 9094):    at com.parse.ParseCorePlugins.getCurrentInstallationController(ParseCorePlugins.java:272)
W/System.err( 9094):    at com.parse.ParseInstallation.getCurrentInstallationController(ParseInstallation.java:52)
W/System.err( 9094):    at com.parse.ParseInstallation.getCurrentInstallation(ParseInstallation.java:57)

Here is my code:

QAndroidJniEnvironment env;

if (!QAndroidJniObject::isClassAvailable("com/parse/Parse")) {
    qDebug() << "com/parse/Parse not available";
    return;
}

if (!QAndroidJniObject::isClassAvailable("com/parse/ParseInstallation")) {
    qDebug() << "com/parse/ParseInstallation not available";
    return;
}

QAndroidJniObject applicationId = QAndroidJniObject::fromString("MY_PARSE_APPLICATION_ID");
QAndroidJniObject clientKey = QAndroidJniObject::fromString("MY_PARSE_CLIENT_ID");
QAndroidJniObject activity = QtAndroid::androidActivity();

if (!activity.isValid()) {
    qDebug() << "invalid activity";
}

QAndroidJniObject application = activity.callObjectMethod("getApplication", "()Landroid/app/Application;");
if (!application.isValid()) {
    qDebug() << "invalid application";
}

qDebug() << env->ExceptionCheck();

QAndroidJniObject::callStaticMethod<void>("com/parse/Parse",
                      "enableLocalDatastore",
                      "(Ljava/lang/object;)V",
                      application.object<jobject>()
                      );
qDebug() << env->ExceptionCheck();

QAndroidJniObject::callStaticMethod<void>("com/parse/Parse",
                      "initialize",
                      "(Ljava/lang/object;Ljava/lang/String;Ljava/lang/String;)V",
                      application.object<jobject>(),
                      applicationId.object<jstring>(),
                      clientKey.object<jstring>()
                      );

qDebug() << env->ExceptionCheck();

// this is where it fails, until here all exception checks show no error:
QAndroidJniObject parseInstallation = QAndroidJniObject::callStaticObjectMethod("com/parse/ParseInstallation",
                                       "getCurrentInstallation",
                                       "()Lcom/parse/ParseInstallation;");

// here ExceptionCheck reports an error for the first time
qDebug() << env->ExceptionCheck();
// this gives the above error message
env->ExceptionDescribe();

if (!parseInstallation.isValid()) {
    qDebug() << "invalid parseInstallation";
    return;
}

My AndroidManifest.xml has the following, right before opening the application tag (myapp is a placeholder, the real application identifier is configured correctly):

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>

<!--
  IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
  to match your app package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature" android:name="myapp.permission.C2D_MESSAGE"/>
<uses-permission android:name="myapp.permission.C2D_MESSAGE"/>

... and the following before the closing application tag:

<service android:name="com.parse.PushService"/>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
  <intent-filter>
    <action android:name="com.parse.push.intent.RECEIVE"/>
    <action android:name="com.parse.push.intent.DELETE"/>
    <action android:name="com.parse.push.intent.OPEN"/>
    </intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
  <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
    <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>

    <!--
      IMPORTANT: Change "com.parse.starter" to match your app package name.
    -->
    <category android:name="myapp"/>
  </intent-filter>
</receiver>

I really used the v-play plugin so far, but it stops working, so I'm trying to implement it myself, which means that the parsing side is configured correctly, because it was used to work with the v-play plugin (so far it stopped working; ) - but this is a mistake on the v-play side)

What am I doing wrong?

+4

Source: https://habr.com/ru/post/1608194/


All Articles