2
\$\begingroup\$

I am making a game for Android with Unity3d.
I've been looking for a solution to this on the web for a little, but I couldn't find anything suitable:

I want to make my game have offline notifications.
Like...I want to set up an alarm that notifies the user at some point in the future e.g.

"Building complete!"

but the app should not have to be running.

How do I accomplish that?

\$\endgroup\$
1
\$\begingroup\$

Short answer: You need to create Unity Android plugin of Android project using Google Cloud Messaging. Details of how to create Android Unity plugin you can find Unity's official site.

Here are some details: A) You have to start with google Android sample app, understand the push-related API methods https://developers.google.com/cloud-messaging/android/start

B)You will need API KEY, SECRET and ANDROID SENDER ID: Project Number assigned when setting up Google Cloud Messaging.

C) Your AndroidManifest.xml. Google Cloud Messaging has some minimum API level requirements for development and testing. Set minSdkVersion property appropriately.

D) Add the following new permissions after the existing element, replacing your_package_namewith the name of the app package for your project. To check the current name of your package go to File > Build Settings > Player Settings and select the Android tab. You will find it in the Bundle Identifier field.

    <permission android:name="**your_package_name**.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="**your_package_name**.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

E) Add the following code after the main activity inside your application tag, replacing it with the name of the app package for your project:

     <activity android:name="com.gamedonia.pushnotifications.GamedoniaPushHandlerActivity" />
     <receiver android:name="com.gamedonia.pushnotifications.PushBroadcastReceiver" 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="**your_package_name**" />
     </intent-filter>
     </receiver>

F) Use your unity functions to call methods written in your Android project, You can send push notifications from a server scripts.

\$\endgroup\$
  • \$\begingroup\$ Thank you for the detailed answer, but I only wanted to use offline notifications. I heared you can create services for android that run in the background, even when the app is not running. Is that possible with unity3d? \$\endgroup\$ – 000000000000000000000 Aug 18 '15 at 8:29
  • \$\begingroup\$ Yes its possible, Push notification by Android's Google Cloud Messaging (GCM) requires a server as well as online connectivity. What you want to do seems to be something different, called local notification: You need to look in to this open source project "Unity3D Plugin for Android local notifications with example project" github.com/Agasper/unity-android-notifications Or if you have 15$ you can get this assetstore.unity3d.com/en/#!/content/9484 \$\endgroup\$ – Rajiv Chandel Aug 18 '15 at 8:42
  • \$\begingroup\$ Thank you very much! Seems very helpfull, I'll give it a try! :D \$\endgroup\$ – 000000000000000000000 Aug 18 '15 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.