is apk package Available - Android android.content.pm

Android examples for android.content.pm:Apk Install

Description

is apk package Available

Demo Code

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {

  public static boolean isAvailable(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    List<String> pName = new ArrayList<String>();
    if (pinfo != null) {
      for (int i = 0; i < pinfo.size(); i++) {
        String pn = pinfo.get(i).packageName;
        pName.add(pn);// w w w  .j a v a2 s . co m
      }
    }
    return pName.contains(packageName);
  }

}

Related Tutorials