get Non System Apk Path Map - Android android.content.pm

Android examples for android.content.pm:Apk Property

Description

get Non System Apk Path Map

Demo Code

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main{

    public static Map<String, PackageInfo> getNonSystemApkPathMap(
            Context context) {/*ww  w .  jav  a2s. c o m*/
        Map<String, PackageInfo> apkMap = new HashMap<String, PackageInfo>();
        List<PackageInfo> packageList = getAllPackages(context);
        if (packageList != null && packageList.size() > 0) {
            for (PackageInfo pkg : packageList) {
                if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                    apkMap.put(pkg.packageName, pkg);
                }
            }
        }
        return apkMap;
    }
    public static List<PackageInfo> getAllPackages(Context context) {
        List<PackageInfo> packageList = new ArrayList<PackageInfo>();
        PackageManager pm = context.getPackageManager();
        packageList = pm.getInstalledPackages(0);
        return packageList;
    }

}

Related Tutorials