Steps to Integrate Push Notification with Unity Sample on Android

Push Notification is widely used to increase user engagement in mobile native apps. push notification android unity Steps to Integrate Push Notification with Unity Sample on AndroidAndroid App developers can use this feature to increase interactions with their users. Push Notifications are always a bit tricky to implement on android devices and if it comes to Unity on Android, it becomes even more complex.

Here is a sample of integrating App42 Push Notification service with Unity3D App. With Unity you can create rich, interactive entertainment or multimedia experience. This blog post will help you learn how to use Unity, push notification feature with App42 Backend as a Service APIs.

App developers can make their games more realistic and can provide multiplayer support by using App42 Push Notification API.

get started Steps to Integrate Push Notification with Unity Sample on Android

Here are the few easy steps to run this sample App:

1. Register with App42 platform.
2. Create an App once you are on the quick start page after registration.
3. If you are an already registered user, login to AppHQ console and create an App from App Manager Tab.
4. Download the sample code from here
5. To use Push Notification service in your application,create a new project in Google API Console
6. Click on services option in Google console and enable Google Cloud Messaging for Android service.
7. Click on API Access tab and create a new server key for your application with blank server information.
8. Go to AppHQ console and click on Push Notification and select Android setting in Settings option.
9. Select your App and copy server key that is generated by using Google API console and submit it.
10.  Open the PushSample.unity from your assets folder, it contains PushSample.cs & Constants.cs.
11.  Open Constants.cs file in sample App and make these changes.

1
2
3
4
A. Change apiKey and secretKey that you have received in step 2 or 3.
B. Change projectNo with your Google Project Number.
C. Change gameObjectName with your GameObject on which you have to receive notfication callBack from Android.
D. Change callBackMethod with your method name on which you have to receive notification callBack from Android e.g. Success.

12. Build your Android apk.

Test and verify PushNotification

1
2
3
4
A. After registering for PushNotification go to AppHQ console and click on Push Notification and select application after selecting User tab.
B. Select desired user from registered UserList and click on Send Message Button.
C. Send appropriate message to user by clicking Send Button.
D. Now you will get same message on your android device and your callBack Method of Unity3D.

System Requirements:

1
2
A. Unity 3D.
B. Android SDK with 4.0 API .

Design Details:

Push Registration: To use Notification message in your game, you have to register your game for Push Notification by calling this method in your main cs file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 public void RegisterForPush(){
        object[] googleProjectNo = new object[]{Constants.GoogleProjectNo};
        object[] unityParam = new object[]{Constants.CallBackMethod,this.gameObject.name,UnityRegistrationMethod};
        using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
            playerActivityContext = actClass.GetStatic<AndroidJavaObject>("currentActivity");
            using (var pluginClass = new AndroidJavaClass("com.shephertz.app42.android.pushservice.App42PushService")) {
                if (pluginClass != null) {
                    testobj = pluginClass.CallStatic<AndroidJavaObject>("instance",playerActivityContext);
                    testobj.Call("setProjectNo",googleProjectNo);
                    testobj.Call("registerForNotification",unityParam);
                }
            }
        }
    }

To Customize sample app follow these steps.

In case you have any more questions, please feel free to reach out to us at support@shephertz.com

twitter Steps to Integrate Push Notification with Unity Sample on Androidfacebook Steps to Integrate Push Notification with Unity Sample on Androidgoogle Steps to Integrate Push Notification with Unity Sample on Androidlinkedin Steps to Integrate Push Notification with Unity Sample on Androidpinterest Steps to Integrate Push Notification with Unity Sample on Androidreddit Steps to Integrate Push Notification with Unity Sample on Androidstumbleupon Steps to Integrate Push Notification with Unity Sample on Androidtumblr Steps to Integrate Push Notification with Unity Sample on Android

Leave a Reply

Your email address will not be published. Required fields are marked *


4 + four =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>