Example #1
0
        /// <summary>
        /// Gets the information of the running applications including subapp asynchronously.
        /// </summary>
        /// <returns>The application running context list.</returns>
        /// <since_tizen> 3 </since_tizen>
        public static async Task <IEnumerable <ApplicationRunningContext> > GetAllRunningApplicationsAsync()
        {
            return(await Task.Run(() =>
            {
                Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
                List <ApplicationRunningContext> result = new List <ApplicationRunningContext>();

                Interop.ApplicationManager.AppManagerAppContextCallback cb = (IntPtr contextHandle, IntPtr userData) =>
                {
                    if (contextHandle != IntPtr.Zero)
                    {
                        IntPtr clonedHandle = IntPtr.Zero;
                        err = Interop.ApplicationManager.AppContextClone(out clonedHandle, contextHandle);
                        if (err != Interop.ApplicationManager.ErrorCode.None)
                        {
                            Log.Warn(LogTag, "Failed to clone the app context. err = " + err);
                            return false;
                        }
                        ApplicationRunningContext context = new ApplicationRunningContext(clonedHandle);
                        result.Add(context);
                        return true;
                    }
                    return false;
                };

                err = Interop.ApplicationManager.AppManagerForeachRunningAppContext(cb, IntPtr.Zero);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    Log.Error(LogTag, "Failed to retrieve the running app context. err " + err.ToString());
                }
                return result;
            }).ConfigureAwait(false));
        }
Example #2
0
        /// <summary>
        /// Gets the information of the installed applications asynchronously.
        /// </summary>
        /// <returns>The installed application info list.</returns>
        /// <since_tizen> 3 </since_tizen>
        public static async Task <IEnumerable <ApplicationInfo> > GetInstalledApplicationsAsync()
        {
            return(await Task.Run(() =>
            {
                Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
                List <ApplicationInfo> result = new List <ApplicationInfo>();

                Interop.ApplicationManager.AppManagerAppInfoCallback cb = (IntPtr infoHandle, IntPtr userData) =>
                {
                    if (infoHandle != IntPtr.Zero)
                    {
                        IntPtr clonedHandle = IntPtr.Zero;
                        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;
                };
                err = Interop.ApplicationManager.AppManagerForeachAppInfo(cb, IntPtr.Zero);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    Log.Error(LogTag, "Failed to retrieve the application Info. err " + err.ToString());
                }
                return result;
            }).ConfigureAwait(false));
        }