Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

clear data of applications installed

$
0
0

Ho can i delete all data(clear data) of all applications installed in my android device?
link bellow :
http://stackoverflow.com/questions/19830706/kill-another-application-and-clear-its-data
converted to C# android xamarin!

` public static void DeleteAllApps(Context _context)
{
Intent mainIntent = new Intent(Intent.ActionMain, null);
mainIntent.AddCategory(Intent.CategoryLauncher);
IList<Android.Content.PM.ResolveInfo> pkgAppsList = _context.PackageManager.QueryIntentActivities(mainIntent, 0);
for (int i = 0; i < pkgAppsList.Count; i++)
{
try
{
ActivityManager activityManager = (ActivityManager)_context.GetSystemService(Context.ActivityService);
activityManager.KillBackgroundProcesses(pkgAppsList[i].ResolvePackageName);
clearApplicationData(pkgAppsList[i].ResolvePackageName, _context);

            }
            catch(Exception ex)
            {
            }
        }

    }
    static void clearApplicationData(String packageName, Context _context)
    {
        File cache = _context.CacheDir;
        File appDir1 = new File(cache.Parent).ParentFile;
        File appDir = new File(appDir1.AbsolutePath + "/" + packageName);
        if (appDir.Exists())
        {
            String[] children = appDir.List();
            foreach (string s in children)
            {
                if (!s.Equals("lib"))
                {
                    deleteDir(new File(appDir, s));
                }
            }

        }
    }
    static bool deleteDir(File dir)
    {
        if (dir != null && dir.IsDirectory)
        {
            String[] children = dir.List();
            for (int i = 0; i < children.Length; i++)
            {
                bool success = deleteDir(new File(dir, children[i]));
                if (!success)
                {
                    return false;
                }
            }
        }
        return dir.Delete();
    }`

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>