Example #1
0
        /// <summary>
        /// Shows the local notification. Upon click it will open the game if the game is not in foreground.
        /// </summary>
        /// <param name="title">Set the title (first row) of the notification, in a standard notification.</param>
        /// <param name="text">Set the text (second row) of the notification, in a standard notification.</param>
        /// <param name="when">Set the time that the event occurred. Notifications in the panel are sorted by this time.</param>
        /// <param name="tickerText">Set the text that is displayed in the status bar when the notification first arrives.</param>
        /// <param name="iconName">Icon drawable name. Icon must be included in the app in res/drawable folder</param>
        public static void ShowNotification(string title, string text,
                                            DateTime?when = null, string tickerText = null, string iconName = null)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            using (var builderAJO = new AndroidJavaObject(CompatBuilderClass, AGUtils.Activity))
            {
                var intent        = new AndroidIntent(AGUtils.GetMainActivityClass());
                var pendingIntent = AndroidPendingIntent.GetActivity(intent.AJO);

                builderAJO.CallAJO("setContentTitle", title);
                builderAJO.CallAJO("setContentText", text);
                builderAJO.CallAJO("setAutoCancel", true);

                builderAJO.CallAJO("setWhen", (when ?? DateTime.Now).ToMillisSinceEpoch());

                int icon = string.IsNullOrEmpty(iconName) ? R.UnityLauncherIcon : R.GetAppDrawableId(iconName);
                builderAJO.CallAJO("setSmallIcon", icon);

                builderAJO.CallAJO("setDefaults", DEFAULT_ALL);
                builderAJO.CallAJO("setContentIntent", pendingIntent);
                //builderAJO.CallAJO("setContentInfo", "Info");
                if (!string.IsNullOrEmpty(tickerText))
                {
                    builderAJO.CallAJO("setTicker", tickerText);
                }

                AGSystemService.NotificationService.Call("notify", 1, builderAJO.CallAJO("build"));
                intent.Dispose();
                pendingIntent.Dispose();
            }
        }
Example #2
0
        /// <summary>
        /// Hides/shows application icon from Launcher.
        /// IMPORTANT: It's somehow tricky if you need to do something with main activity in your app when it's hidden.
        /// You will face an ActivityNotFoundException. To make it work, you should show icon
        /// before doing anything to your main activity and hide it again after you are finished.
        /// </summary>
        public static void ChangeApplicationIconState(bool show)
        {
            var componentName = new AndroidJavaObject(C.AndroidContentComponentName, AGUtils.Activity, AGUtils.GetMainActivityClass());

            using (AGUtils.PackageManager)
            {
                AGUtils.PackageManager.Call("setComponentEnabledSetting", componentName, show ? (int)ComponentEnabledState.Enabled : (int)ComponentEnabledState.Disabled,
                                            DoNotKillAppFlag);
            }
        }