1
1

Hi, I have been trying to set up push notifications for Unity Android, and post registration to GCM the app seems to crash.

Manifest

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installlocation="preferExternal" android:theme="@android:style/Theme.NoTitleBar" package="com.RMG.PN3" android:versionname="1.0" android:versioncode="1"> <supports-screens android:smallscreens="true" android:normalscreens="true" android:largescreens="true" android:xlargescreens="true" android:anydensity="true"/> <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true"> <meta-data android:name="PW_APPID" android:value="60C19-331079"/> <meta-data android:name="PW_PROJECT_ID" android:value="A538721688848"/> <meta-data android:name="PW_BROADCAST_PUSH" android:value="true"/> <activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:launchmode="singleTask" android:label="@string/app_name" android:configchanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenorientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <intent-filter> <action android:name="com.RMG.PN3.MESSAGE"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> <activity android:name="com.unity3d.player.UnityPlayerActivity" android:launchmode="singleTask" android:label="@string/app_name" android:configchanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenorientation="portrait"></activity> <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:launchmode="singleTask" android:label="@string/app_name" android:configchanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenorientation="portrait"> <meta-data android:name="android.app.lib_name" android:value="unity"/> <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false"/> </activity> <activity android:name="com.arellomobile.android.push.PushWebview"/> <activity android:name="com.arellomobile.android.push.MessageActivity"/> <activity android:name="com.arellomobile.android.push.PushHandlerActivity"/> <!-- BroadcastReceiver that will receive intents from GCM services and handle them to the custom IntentService.

      The com.google.android.c2dm.permission.SEND permission is necessary
      so only GCM services can send data messages for the app.
    -->
    <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.RMG.PN3" />
        </intent-filter>
    </receiver>
    <!--
      Application-specific subclass of PushGCMIntentService that will
      handle received messages.
    -->
    <service android:name="com.arellomobile.android.push.PushGCMIntentService" />
    <receiver android:name="com.arellomobile.android.push.AlarmReceiver"></receiver>
</application>
<uses-feature android:glEsVersion="0x00020000" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--library-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
  Creates a custom permission so only this app can receive its messages.

  NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
        where PACKAGE is the application's package name.
-->
<permission android:name="com.RMG.PN3.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.RMG.PN3.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

</manifest>

MyScript

using UnityEngine;

using System; using System.Collections; using System.Collections.Generic;

public class Starter : MonoBehaviour { private static AndroidJavaObject pushwoosh = null;

// Use this for initialization
void Start () {
    Debug.Log("in startAGAIn");
    print ("start");
    InitPushwoosh();
    print ("AFTER INITPUSH");
    registerForPushNotifications();
    print ("AFTER REGPUSH");

}

void InitPushwoosh() {
    if(pushwoosh != null)
        return;
    print ("IN INITPUSH pushwoosh not null");
    using(var pluginClass = new AndroidJavaClass("com.arellomobile.android.push.PushwooshProxy"))
        pushwoosh = pluginClass.CallStatic<AndroidJavaObject>("instance");

    pushwoosh.Call("setListenerName", this.gameObject.name);
}

public void registerForPushNotifications()
{
    pushwoosh.Call("registerForPushNotifications");
}


public void setIntTag(string tagName, int tagValue)
{
    print ("setIntTag");
    pushwoosh.Call("setIntTag", tagName, tagValue);
}


// Update is called once per frame
void Update () {

}

public void unregisterForPushNotifications()

{
    pushwoosh.Call("unregisterFromPushNotifications");
}

public void setStringTag(string tagName, string tagValue)
{
    pushwoosh.Call("setStringTag", tagName, tagValue);
}

public void setListTag(string tagName, List<object> tagValues)
{
    AndroidJavaObject tags = new AndroidJavaObject ("com.arellomobile.android.push.TagValues");

    foreach( var tagValue in tagValues )
    {
        tags.Call ("addValue", tagValue);
    }

    pushwoosh.Call ("setListTag", tagName, tags);
}

public void sendLocation(double lat, double lon)
{
    pushwoosh.Call("sendLocation", lat, lon);
}

public void startTrackingGeoPushes()
{
    pushwoosh.Call("startTrackingGeoPushes");
}

public void stopTrackingGeoPushes()
{
    pushwoosh.Call("stopTrackingGeoPushes");
}

public void clearLocalNotifications()
{
    pushwoosh.Call("clearLocalNotifications");
}

public void scheduleLocalNotification(string message, int seconds)
{
    pushwoosh.Call("scheduleLocalNotification", message, seconds);
}

public void scheduleLocalNotification(string message, int seconds, string userdata)
{
    pushwoosh.Call("scheduleLocalNotification", message, seconds, userdata);
}

public void setMultiNotificationMode()
{
    pushwoosh.Call("setMultiNotificationMode");
}

public void setSimpleNotificationMode()
{
    pushwoosh.Call("setSimpleNotificationMode");
}

/* 
 * Sound notification types:
 * 0 - default mode
 * 1 - no sound
 * 2 - always
 */
public void setSoundNotificationType(int soundNotificationType)
{
    pushwoosh.Call("setSoundNotificationType", soundNotificationType);
}

/* 
 * Vibrate notification types:
 * 0 - default mode
 * 1 - no vibrate
 * 2 - always
 */
public void setVibrateNotificationType(int vibrateNotificationType)
{
    pushwoosh.Call("setVibrateNotificationType", vibrateNotificationType);
}

public void setLightScreenOnNotification(bool lightsOn)
{
    pushwoosh.Call("setLightScreenOnNotification", lightsOn);
}

public void setEnableLED(bool ledOn)
{
    pushwoosh.Call("setEnableLED", ledOn);
}

public string getPushToken()
{
    print ("getPushToken");

    return pushwoosh.Call<string>("getPushToken");
}

public string getPushwooshHWID()
{
    print ("getPushwooshHWID");

    return pushwoosh.Call<string>("getPushwooshHWID");
}

void onRegisteredForPushNotifications(string token)
{
    print ("onRegisteredForPushNotifications");
    //do handling here
    Debug.Log(token);
}

void onFailedToRegisteredForPushNotifications(string error)
{
    print ("onFailedToRegisteredForPushNotifications");
    //do handling here
    Debug.Log(error);
}

void onPushNotificationsReceived(string payload)
{
    print ("onPushNotificationsReceived");

    //do handling here
    Debug.Log(payload);
}
void OnApplicationPause(bool paused)
{
    print ("OnApplicationPause");


    //make sure everything runs smoothly even if pushwoosh is not initialized yet
    if (pushwoosh == null)
        InitPushwoosh();

    if(paused)
    {
        pushwoosh.Call("onPause");
    }
    else
    {
        pushwoosh.Call("onResume");
    }
}

}

asked 23 May '14, 15:37
kunalkapur's gravatar image

kunalkapur
2113

like to add that the app crashes before it registers the device with pushwoosh, cant see any subscribers in my control panel.

permanent link
answered 23 May '14, 15:49
kunalkapur's gravatar image

kunalkapur
2113

If the app crashes then it would be best to add the crash log to the original post.

(15 Jan, 09:39) LKWD JamesD LKWD%20JamesD's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×446
×141
×88
×47

question asked: 23 May '14, 15:37

question was seen: 2,822 times

last updated: 15 Jan, 09:39