如何获取仅由用户安装的应用程序列表
到目前为止,我仅尝试过滤系统应用程序,但是没有运气,这给了我所有应用程序的列表,包括系统应用程序。
InstalledApp类
public class InstalledApps
{
public string appName { get; set; }
public string packageName { get; set; }
public string icon { get; set; }
}
获取列表
public List<InstalledApps> getInstalledApp()
{
List<InstalledApps> installedApps = new List<InstalledApps>();
try
{
var apps = Android.App.Application.Context.PackageManager.GetInstalledApplications(PackageInfoFlags.MetaData);
if (apps!=null)
{
if (apps.Count>0)
{
for (int i = 0; i < apps.Count; i++)
{
var info = ctx.PackageManager.GetPackageInfo(apps[i].PackageName, 0);
if (isSystemPackage(info)==false)
{
InstalledApps installapps = new InstalledApps()
{
appName = apps[i].LoadLabel(Android.App.Application.Context.PackageManager),
packageName = apps[i].PackageName,
icon = apps[i].LoadIcon(Android.App.Application.Context.PackageManager).ToString()
};
installedApps.Add(installapps);
}
}
//demo
makeToast($"total installed {apps.Count}");
return installedApps;
}
}
}
catch (Exception ex)
{
//do something with error
}
return installedApps;
}
检查是否有系统应用
private bool isSystemPackage(PackageInfo pkgInfo)
{
return ((pkgInfo.ApplicationInfo.Flags & ApplicationInfoFlags.System) != 0);
}
请帮助。