Notification is received but not displayed using Parse Unity SDK + Android

456 Views Asked by At

I'm using Parse Unity SDK for Android.

I've managed to register the device successfully.

void Start() {
    //Parse Installation
    if (ParseInstallation.CurrentInstallation != null && !string.IsNullOrEmpty(ParseInstallation.CurrentInstallation.DeviceToken))
    {
        Debug.Log("Device Token : " + ParseInstallation.CurrentInstallation.DeviceToken);
    }
    else
    {
        ParseInstallation installation = ParseInstallation.CurrentInstallation;
        installation.Channels = new List<string> { Config.Instance.GetUserInfo().GetEmail() };
        installation.SaveAsync().ContinueWith(t => {
            if (t.IsFaulted || t.IsCanceled)
            {
                Debug.Log("Push subscription failed.");
            }
            else
            {
                Debug.Log("Push subscription success.");
            }
        });


        //installation.
    }
}

Only to discover that the notification is "received" but not being displayed neither in the app nor in the notifications bar.

I/GCM     ( 1285): GCM message com.ahmed.app 0:1433935471473270%3f8fc5dbf9fd7ecd
I/ParsePushService( 7057): Push notification received. Payload: {"alert":"test","push_hash":"098f6bcd4621d373cade4e832627b4f6"}
I/ParsePushService( 7057): Push notification is handled while the app is foregrounded.
W/GCM-DMM ( 1285): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.ahmed.app (has extras) }

Also, Unity does not receive the notification (see code)

void Awake() {
        ParsePush.ParsePushNotificationReceived += (sender, args) => {
            #if UNITY_ANDROID
            AndroidJavaClass parseUnityHelper = new AndroidJavaClass("com.parse.ParseUnityHelper");
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

            //Debugging the payload
            Debug.Log("Calling Parse from Unity and Payload is : " + args.StringPayload);

            // Call default behavior.
            parseUnityHelper.CallStatic("handleParsePushNotificationReceived", currentActivity, args.StringPayload);


            #endif
        };
    }

This event doesn't get triggered.

Here's my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ahmed.app" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />

    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="com.android.vending.BILLING" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <permission android:protectionLevel="signature" android:name="com.ahmed.app.permission.C2D_MESSAGE" />
  <uses-permission android:name="com.ahmed.app.permission.C2D_MESSAGE" />

  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>
    <meta-data android:name="com.google.android.gms.version" android:value="4030500" />
    <activity android:name="com.outlinegames.unibill.PurchaseActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />       
    <service android:name="com.parse.ParsePushService" /> 
    <receiver android:name="com.parse.ParsePushBroadcastReceiver" 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" />
            <category android:name="com.ahmed.app" />
        </intent-filter>
    </receiver>
  </application>

Any idea what's the problem?

2

There are 2 best solutions below

0
On BEST ANSWER

Rather than downloading the SDK manually, I've downloaded the Parse Push sample project and copied the files to my project. Using the SDK 1.5.2 sample project, it works now.

1
On

I have answered the same kind of question, I just wanted to let you know.

Parse Unity Push Sample not working

Basically, this line of your code is wrong:

 AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

You have to replace it by

 AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("com.unity3d.player.UnityPlayerNativeActivity");