
com.hadoopz.MyDroidLib.util.IDroidUtils Maven / Gradle / Ivy
/*
* Copyright 2018 jw362j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hadoopz.MyDroidLib.util;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import java.util.List;
/**
*
* @author jw362j
*/
public class IDroidUtils {
public static boolean isPackageExists(Context context, String packageName) {
if (context == null || TextUtils.isEmpty(packageName)) {
return false;
}
PackageManager pm = context.getPackageManager();
List packages = pm.getInstalledApplications(0);
for (ApplicationInfo packageInfo : packages) {
if (packageName.equals(packageInfo.packageName)) {
return true;
}
}
return false;
}
public static void loadAllPackage(Context context,List packages) {
if (context == null || packages == null) {
return ;
}
PackageManager pm = context.getPackageManager();
List appInfos = pm.getInstalledApplications(0);
for (ApplicationInfo packageInfo : appInfos) {
packages.add(packageInfo.packageName);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy