/// <summary> /// Set badge counter for application with given id. /// </summary> /// <param name="appId">ID of the application.</param> /// <param name="badgeCount">New counter value.</param> public void SetBadge(string appId, int badgeCount) { try { BadgeControl.Add(new Badge(appId, badgeCount, true)); } catch (Exception e) { Debug.WriteLine($"Error setting badge for {appId}: {e.Message}"); } }
/// <summary> /// This function removes badge from current application. /// </summary> private void ResetBadge() { BadgeValue = 0; try { BadgeControl.Remove(applicationId); } catch (Exception e) { Log.Debug("Badges", $"Error when removing badge. {e.GetType()}, {e.Message}"); } }
/// <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); } }
/// <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> /// Class constructor. The constructor is used to initialize the badge counters. /// </summary> public BadgeController() { try { if (!(BadgeControl.GetBadges() is List <Badge> badges)) { global::Tizen.Log.Error(((Program)Application.Current).LogTag, "No badges found"); return; } } catch (Exception e) { global::Tizen.Log.Error(((Program)Application.Current).LogTag, "BadgeControl exception: " + e.Message); } BadgeControl.Changed += BadgeControlOnChanged; }
/// <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); }
public void SetBadge(int?value) { var appId = Application.Current.ApplicationInfo.ApplicationId; try { BadgeControl.Remove(appId); } catch (InvalidOperationException) { // This exception is thrown when the badge does not exist. // Seems there is no way to check if the badge exists. } if (value != null) { Badge badge = new Badge(appId, value.Value); BadgeControl.Add(badge); } }
/// <summary> /// This Function sets badge value of current application to BadgeValue. /// </summary> private void ApplyBadge() { Badge current = GetBadge(); try { if (current == null) { BadgeControl.Add(new Badge(applicationId, BadgeValue)); } else { current.Count = BadgeValue; current.Visible = true; BadgeControl.Update(current); } } catch (Exception e) { Log.Debug("Badges", $"Failed to set badge count. {e.GetType()}, {e.Message}"); } }