Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.HashMap;
import java.util.List;

import java.util.Map;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

public class Main {
    private static long sInstalledAppsLastUpdated = System.currentTimeMillis();
    private static Map<String, Void> sInstalledApps = null;

    public static void initInstalledAppCache(final Context ctx, boolean forceRefresh) {
        if (sInstalledApps != null && !forceRefresh) {
            return;
        }
        final PackageManager pm = ctx.getPackageManager();
        final List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
        Map<String, Void> iapps = new HashMap<String, Void>(packages.size());
        for (final ApplicationInfo packageInfo : packages) {
            iapps.put(packageInfo.packageName, null);
        }
        sInstalledApps = iapps;
        sInstalledAppsLastUpdated = System.currentTimeMillis();
    }
}