Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CarreraSilvio · Jun 18, 2014 at 01:10 PM · androidnotification

Notification on Android

I'm trying to send a notification via Android but it isn't working properly.

Here is my java code:

 public class MainActivity extends UnityPlayerNativeActivity {

 private static Context context;

 private static Notification mNotification;

 private static NotificationManager mNotificationManager;
 
 
 @Override
 protected void onStart() {
     // TODO Auto-generated method stub
     super.onStart();
     context = this;
 }
 
 @Override
 protected void onResume() {
     // TODO Auto-generated method stub
     super.onResume();
     context = this;
 }

 public static String GetString() {

     return "java: hello";
 }
 
 public static void NotifyUser()
 {
     Log.d("yoob", "NotifyUser");
     Log.d("yoob", "Start");
     Resources res = context.getResources();
     int icon = res.getIdentifier("yoobsicon", "drawable", context.getPackageName());
 
     
     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
             context).setSmallIcon(icon)
             .setContentTitle("Yoob diz:")
             .setContentText("Fome da mizera!");
     mNotification = mBuilder.build();
     Log.d("yoob", "middle");
     mNotificationManager = (NotificationManager) context
             .getSystemService(Context.NOTIFICATION_SERVICE);
     mNotificationManager.notify(123, mNotification);
     Log.d("yoob", "end");
     

 }

}

And here's my Unity code:

 using UnityEngine;
 using System.Collections;
 
 public class NumberExample : MonoBehaviour {
 
     public string message = "mensagem";
 
     public TextMesh textMesh;
 
     private int count = 0;
 
     #if UNITY_ANDROID && !UNITY_EDITOR
     AndroidJavaClass pluginPlugAndPlay;
     #endif
     
     void Start () 
     {
         #if UNITY_ANDROID && !UNITY_EDITOR
         AndroidJNI.AttachCurrentThread();
         pluginPlugAndPlay = new AndroidJavaClass("com.cesar.yoobs.MainActivity");
         #endif
 
         //textMesh.text = message;
     }
     
     void Update()
     {
         #if UNITY_ANDROID && !UNITY_EDITOR
         message   = pluginPlugAndPlay.CallStatic<string>("GetString");
         count++;
         if(count == 100) pluginPlugAndPlay.CallStatic("NotifyUser");
         #endif
         message = message + " " + count;
         textMesh.text = message;
 
 
     }
 
 }

If I build my java code directly to android it works fine and I get the proper notification. On Eclipse I get a nullPointerException which I think it has to do with him not finding the icon when on Unity. I have everything set in Plugins/Android/res as I've seen other people mentioning here. Is there anything else I should be doing?

Thanks in advance.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dave-Hampson ♦♦ · Dec 22, 2014 at 11:47 AM 0
Share

Hi there,

I just want to try to work out the context of your question, so I can help you get exactly what you are after.

Are you trying to produce a notification ( http://developer.android.com/guide/topics/ui/notifiers/notifications.html ) based on something happening in your game?

What kind of event are you looking to trigger an event from. What happens in your game? What kind of game is it exactly? Why a notification rather than just displaying something on the screen? (The reason I ask is, in my experience, a notification is usually sent by a background application like an email client to prompt the user to bring the application to the foreground.) What should happen when they tap the notification?

Dave

avatar image Ben-Stoneman ♦♦ · Jan 21, 2015 at 03:44 PM 0
Share

This post should help also:

http://forum.unity3d.com/threads/push-notifications-on-unity-android.126528/

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Custom push notification sound in android build doesn't work 0 Answers

Android Push Notifications stopped working using GMS? 0 Answers

Send Push Notifications to Android Device 5 Answers

Free Android local notification plugin 1 Answer

How to call an android notification plugin if it's not the main activity? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges