check if package name exists - Android App

Android examples for App:Package

Description

check if package name exists

Demo Code


//package com.java2s;
import java.util.List;

import android.content.Context;
import android.content.Intent;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

public class Main {
    public static boolean exists(Context context, String pakgename) {

        PackageManager manager = context.getPackageManager();
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        final List<ResolveInfo> apps = manager.queryIntentActivities(
                mainIntent, 0);//  w  w w.  ja  v  a 2 s.  co m

        final int count = apps.size();
        ResolveInfo info = null;
        for (int i = 0; i < count; i++) {
            info = apps.get(i);
            if (pakgename.equals(info.activityInfo.packageName)) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials