Exemplo n.º 1
0
        /// <summary>
        /// Initialize the AndroidNotificationCenter class.
        /// Can be safely called multiple times
        /// </summary>
        /// <returns>True if has been successfully initialized</returns>
        public static bool Initialize()
        {
            if (s_Initialized)
            {
                return(true);
            }

            if (AndroidReceivedNotificationMainThreadDispatcher.GetInstance() == null)
            {
                var receivedNotificationDispatcher = new GameObject("AndroidReceivedNotificationMainThreadDispatcher");
                receivedNotificationDispatcher.AddComponent <AndroidReceivedNotificationMainThreadDispatcher>();
            }

#if UNITY_EDITOR || !UNITY_ANDROID
            s_CurrentActivity = null;
#elif UNITY_ANDROID
            var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            s_CurrentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            var context = s_CurrentActivity.Call <AndroidJavaObject>("getApplicationContext");

            var notificationManagerClass = new AndroidJavaClass("com.unity.androidnotifications.UnityNotificationManager");
            var notificationManager      = notificationManagerClass.CallStatic <AndroidJavaObject>("getNotificationManagerImpl", context, s_CurrentActivity);
            notificationManager.Call("setNotificationCallback", new NotificationCallback());
            s_Jni = new JniApi(notificationManagerClass, notificationManager);

            s_Initialized = true;
#endif
            return(s_Initialized);
        }
Exemplo n.º 2
0
 void CollectFields(AndroidJavaClass clazz)
 {
     extras = JniApi.FindField(clazz, "extras", "Landroid/os/Bundle;", false);
     flags  = JniApi.FindField(clazz, "flags", "I", false);
     number = JniApi.FindField(clazz, "number", "I", false);
     when   = JniApi.FindField(clazz, "when", "J", false);
 }
Exemplo n.º 3
0
 void CollectMethods(AndroidJavaClass clazz)
 {
     getNotificationFromIntent         = JniApi.FindMethod(clazz, "getNotificationFromIntent", "(Landroid/content/Context;Landroid/content/Intent;)Landroid/app/Notification;", true);
     setNotificationIcon               = JniApi.FindMethod(clazz, "setNotificationIcon", "(Landroid/app/Notification$Builder;Ljava/lang/String;Ljava/lang/String;)V", true);
     setNotificationColor              = JniApi.FindMethod(clazz, "setNotificationColor", "(Landroid/app/Notification$Builder;I)V", true);
     getNotificationColor              = JniApi.FindMethod(clazz, "getNotificationColor", "(Landroid/app/Notification;)Ljava/lang/Integer;", true);
     setNotificationUsesChronometer    = JniApi.FindMethod(clazz, "setNotificationUsesChronometer", "(Landroid/app/Notification$Builder;Z)V", true);
     setNotificationGroupAlertBehavior = JniApi.FindMethod(clazz, "setNotificationGroupAlertBehavior", "(Landroid/app/Notification$Builder;I)V", true);
     getNotificationGroupAlertBehavior = JniApi.FindMethod(clazz, "getNotificationGroupAlertBehavior", "(Landroid/app/Notification;)I", true);
     getNotificationChannelId          = JniApi.FindMethod(clazz, "getNotificationChannelId", "(Landroid/app/Notification;)Ljava/lang/String;", true);
     scheduleNotification              = JniApi.FindMethod(clazz, "scheduleNotification", "(Landroid/app/Notification$Builder;)I", false);
     createNotificationBuilder         = JniApi.FindMethod(clazz, "createNotificationBuilder", "(Ljava/lang/String;)Landroid/app/Notification$Builder;", false);
 }
Exemplo n.º 4
0
 public void CollectJni()
 {
     using (var clazz = new AndroidJavaClass("android/os/Bundle"))
     {
         containsKey = JniApi.FindMethod(clazz, "containsKey", "(Ljava/lang/String;)Z", false);
         getBoolean  = JniApi.FindMethod(clazz, "getBoolean", "(Ljava/lang/String;Z)Z", false);
         getInt      = JniApi.FindMethod(clazz, "getInt", "(Ljava/lang/String;I)I", false);
         getLong     = JniApi.FindMethod(clazz, "getLong", "(Ljava/lang/String;J)J", false);
         getString   = JniApi.FindMethod(clazz, "getString", "(Ljava/lang/String;)Ljava/lang/String;", false);
         putBoolean  = JniApi.FindMethod(clazz, "putBoolean", "(Ljava/lang/String;Z)V", false);
         putInt      = JniApi.FindMethod(clazz, "putInt", "(Ljava/lang/String;I)V", false);
         putLong     = JniApi.FindMethod(clazz, "putLong", "(Ljava/lang/String;J)V", false);
         putString   = JniApi.FindMethod(clazz, "putString", "(Ljava/lang/String;Ljava/lang/String;)V", false);
     }
 }
Exemplo n.º 5
0
 public void CollectJni()
 {
     using (var clazz = new AndroidJavaClass("android.app.Notification$Builder"))
     {
         getExtras       = JniApi.FindMethod(clazz, "getExtras", "()Landroid/os/Bundle;", false);
         setContentTitle = JniApi.FindMethod(clazz, "setContentTitle", "(Ljava/lang/CharSequence;)Landroid/app/Notification$Builder;", false);
         setContentText  = JniApi.FindMethod(clazz, "setContentText", "(Ljava/lang/CharSequence;)Landroid/app/Notification$Builder;", false);
         setAutoCancel   = JniApi.FindMethod(clazz, "setAutoCancel", "(Z)Landroid/app/Notification$Builder;", false);
         setNumber       = JniApi.FindMethod(clazz, "setNumber", "(I)Landroid/app/Notification$Builder;", false);
         setStyle        = JniApi.FindMethod(clazz, "setStyle", "(Landroid/app/Notification$Style;)Landroid/app/Notification$Builder;", false);
         setWhen         = JniApi.FindMethod(clazz, "setWhen", "(J)Landroid/app/Notification$Builder;", false);
         setGroup        = JniApi.FindMethod(clazz, "setGroup", "(Ljava/lang/String;)Landroid/app/Notification$Builder;", false);
         setGroupSummary = JniApi.FindMethod(clazz, "setGroupSummary", "(Z)Landroid/app/Notification$Builder;", false);
         setSortKey      = JniApi.FindMethod(clazz, "setSortKey", "(Ljava/lang/String;)Landroid/app/Notification$Builder;", false);
         setShowWhen     = JniApi.FindMethod(clazz, "setShowWhen", "(Z)Landroid/app/Notification$Builder;", false);
     }
 }
Exemplo n.º 6
0
 void CollectMethods(AndroidJavaClass clazz)
 {
     getGroup   = JniApi.FindMethod(clazz, "getGroup", "()Ljava/lang/String;", false);
     getSortKey = JniApi.FindMethod(clazz, "getSortKey", "()Ljava/lang/String;", false);
 }