【问题标题】:how to identify a Foreground activity is an System Activity or an INSTALLED App in Android?如何识别前台活动是 Android 中的系统活动或已安装的应用程序?
【发布时间】:2013-06-10 12:52:43
【问题描述】:

我正在处理我的应用程序中的系统应用程序处理。我已经在我的应用程序中生成了 Android 设备中所有已安装应用程序的完整列表。现在我的任务是从该应用程序列表中识别系统应用程序。或者确定当前前台应用是系统应用还是安装应用?

目前使用以下代码:

PackageManager packageManager = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0);
Collections.sort(appList, new ResolveInfo.DisplayNameComparator(packageManager));

List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA
for(int i=0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1))
{
continue;
}

apps.add(p.packageName);

【问题讨论】:

    标签: android system installed-applications


    【解决方案1】:

    以下代码区分了系统应用和已安装的应用。

    List<ApplicationInfo> installedApps = getPackageManager().getInstalledApplications(0);
        for (int i = 0; i < installedApps.size(); i++) {
            if(installedApps.get(i).sourceDir.startsWith("/data/app/")){
            //Non System Apps
            }else{
            //system Apps
            }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多