Push Notification is widely used to increase user engagement in mobile native apps. Android 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.
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. If you want integrate in your existing Unity project import App42UnityPushPlugin package by selecting custom asset import option in Assets or you can import unity project in Unity IDE..
11. Attach PushSample.cs file on Main Camera if not attached and make following changes
A. Change ApiKey and SecretKey that you have received in step 2 or 3 at line no 22 and 23. B. Change GoogleProjectNo with your Google Project Number at line no 24. C. Change UserId with your username you want tp register for Push Notification at line no 25. .
12. Build your Android apk.
Test and verify PushNotification
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.
A. Unity 3D. B. Android SDK with 4.0 API .
Push Registration: To use Notification message in your game, you have to register your game for Push Notification by adding following code snippet in Start() method of your main cs file.
App42API.Initialize("App42 API Key","App42 Secret Key"); //which you want to register for Push Notification App42API.SetLoggedInUser("App42 userId"); //prior implement App42NativePushListener in you script file App42Push.setApp42PushListener (this); #if UNITY_ANDROID App42Push.registerForPush ("Your Google Project No"); message=App42Push.getLastPushMessage(); #endif
To Customize sample app follow these steps.
In case you have any more questions, please feel free to reach out to us at email@example.com