Beispiel #1
0
        /// <summary>
        /// Returns information about all available applications supplemented with badge counter data and flag indicates
        /// whether app was installed by current user or not.
        /// </summary>
        /// <param name="applicationListCb">Delegate to call on every application retrieval.</param>
        public async void GetAppList(AddAppToListDelegate applicationListCb)
        {
            var myCert = PackageManager.GetPackage(Application.Current.ApplicationInfo.PackageId)?
                         .Certificates[CertificateType.Author].Signer;
            IEnumerable <ApplicationInfo> installedApplications =
                await ApplicationManager.GetInstalledApplicationsAsync();

            foreach (ApplicationInfo tizenAppInfo in installedApplications)
            {
                if (tizenAppInfo.IsNoDisplay)
                {
                    continue;
                }

                Package pkg;
                try
                {
                    pkg = PackageManager.GetPackage(tizenAppInfo.PackageId);
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Error getting application {tizenAppInfo.ApplicationId} information: {e.Message}");
                    continue;
                }

                var appSignerCert = pkg?.Certificates[CertificateType.Author].Signer;
                if (appSignerCert == null)
                {
                    continue;
                }

                bool isEnabled = appSignerCert.Equals(myCert);
                var  appInfo   = new AppInfo(
                    appName: tizenAppInfo.Label,
                    appId: tizenAppInfo.ApplicationId,
                    isAvailable: isEnabled,
                    badgeCounter: 0);
                try
                {
                    Badge badge = BadgeControl.Find(appInfo.AppId);
                    if (badge != null)
                    {
                        appInfo.BadgeCounter = Convert.ToDouble(badge.Count);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Error getting badge for {appInfo.AppId}: {e.Message}");
                }

                applicationListCb(appInfo);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns badge for current application.
        /// If current application has no badge returns null.
        /// </summary>
        /// <returns> Found badge </returns>
        private Badge GetBadge()
        {
            Badge badge = null;

            try
            {
                badge = BadgeControl.Find(applicationId);
            }
            catch (Exception e)
            {
                Log.Debug("Badges", $"Failed to find badge. {e.GetType()}, {e.Message}");
            }
            return(badge);
        }
        /// <summary>
        /// Set the number of events or notifications to show on the badge.
        /// </summary>
        /// <param name="count">Number of events or notifications</param>
        public static void SetCount(uint count)
        {
            if (_badge == null)
            {
                try
                {
                    _badge = BadgeControl.Find(_appId);
                }
                catch (InvalidOperationException)
                {
                    // An exception is thrown when the app tries to access a badge before it is added.
                    _badge = new Badge(_appId, count: 0, visible: true);
                    BadgeControl.Add(_badge);
                }
            }

            _badge.Count = (int)count;
            BadgeControl.Update(_badge);
        }