internal static void Fetch(this ApplicationInfoFilter filter, Interop.ApplicationManager.AppInfoFilterCallback callback) { if (filter is ApplicationInfoMetadataFilter) { ApplicationInfoMetadataFilter metaFilter = (ApplicationInfoMetadataFilter)filter; metaFilter.Fetch(callback); return; } IntPtr nativeHandle = MakeNativeAppInfoFilter(filter.Filter); if (nativeHandle == IntPtr.Zero) { throw ApplicationManagerErrorFactory.NativeFilterHandleIsInvalid(); } try { Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppInfoFilterForeachAppinfo(nativeHandle, callback, IntPtr.Zero); if (err != Interop.ApplicationManager.ErrorCode.None) { throw ApplicationManagerErrorFactory.GetException(err, "Failed to get application information list with filter."); } } finally { Interop.ApplicationManager.AppInfoFilterDestroy(nativeHandle); } }
/// <summary> /// Gets the information of the installed applications with the ApplicationInfoFilter asynchronously. /// </summary> /// <param name="filter">Key-value pairs for filtering.</param> /// <returns>The installed application info list.</returns> /// <since_tizen> 3 </since_tizen> public static async Task <IEnumerable <ApplicationInfo> > GetInstalledApplicationsAsync(ApplicationInfoFilter filter) { return(await Task.Run(() => { List <ApplicationInfo> result = new List <ApplicationInfo>(); Interop.ApplicationManager.AppInfoFilterCallback cb = (IntPtr infoHandle, IntPtr userData) => { if (infoHandle != IntPtr.Zero) { IntPtr clonedHandle = IntPtr.Zero; Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppInfoClone(out clonedHandle, infoHandle); if (err != Interop.ApplicationManager.ErrorCode.None) { Log.Warn(LogTag, "Failed to clone the appinfo. err = " + err); return false; } ApplicationInfo app = new ApplicationInfo(clonedHandle); result.Add(app); return true; } return false; }; filter.Fetch(cb); return result; }).ConfigureAwait(false)); }