use of android.content.pm.PackageInfo in project DroidPlugin by DroidPluginTeam.
the class StaticProcessList method onCreate.
void onCreate(Context mHostContext) throws NameNotFoundException {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(CATEGORY_ACTIVITY_PROXY_STUB);
intent.setPackage(mHostContext.getPackageName());
PackageManager pm = mHostContext.getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
for (ResolveInfo activity : activities) {
addActivityInfo(activity.activityInfo);
}
List<ResolveInfo> services = pm.queryIntentServices(intent, 0);
for (ResolveInfo service : services) {
addServiceInfo(service.serviceInfo);
}
PackageInfo packageInfo = pm.getPackageInfo(mHostContext.getPackageName(), PackageManager.GET_PROVIDERS);
if (packageInfo.providers != null && packageInfo.providers.length > 0) {
for (ProviderInfo providerInfo : packageInfo.providers) {
if (providerInfo.name != null && providerInfo.name.startsWith(ContentProviderStub.class.getName())) {
addProviderInfo(providerInfo);
}
}
}
mOtherProcessNames.clear();
PackageInfo packageInfo1 = pm.getPackageInfo(mHostContext.getPackageName(), PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS | PackageManager.GET_SERVICES);
if (packageInfo1.activities != null) {
for (ActivityInfo info : packageInfo1.activities) {
if (!mOtherProcessNames.contains(info.processName) && !items.containsKey(info.processName)) {
mOtherProcessNames.add(info.processName);
}
}
}
if (packageInfo1.receivers != null) {
for (ActivityInfo info : packageInfo1.receivers) {
if (!mOtherProcessNames.contains(info.processName) && !items.containsKey(info.processName)) {
mOtherProcessNames.add(info.processName);
}
}
}
if (packageInfo1.providers != null) {
for (ProviderInfo info : packageInfo1.providers) {
if (!mOtherProcessNames.contains(info.processName) && !items.containsKey(info.processName)) {
mOtherProcessNames.add(info.processName);
}
}
}
if (packageInfo1.services != null) {
for (ServiceInfo info : packageInfo1.services) {
if (!mOtherProcessNames.contains(info.processName) && !items.containsKey(info.processName)) {
mOtherProcessNames.add(info.processName);
}
}
}
}
use of android.content.pm.PackageInfo in project AndroidUtilCode by Blankj.
the class AppUtils method getAppPath.
/**
* 获取App路径
*
* @param context 上下文
* @param packageName 包名
* @return App路径
*/
public static String getAppPath(Context context, String packageName) {
if (StringUtils.isSpace(packageName))
return null;
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return pi == null ? null : pi.applicationInfo.sourceDir;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}
use of android.content.pm.PackageInfo in project AndroidUtilCode by Blankj.
the class AppUtils method getAppSignature.
/**
* 获取App签名
*
* @param context 上下文
* @param packageName 包名
* @return App签名
*/
@SuppressLint("PackageManagerGetSignatures")
public static Signature[] getAppSignature(Context context, String packageName) {
if (StringUtils.isSpace(packageName))
return null;
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
return pi == null ? null : pi.signatures;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}
use of android.content.pm.PackageInfo in project AndroidUtilCode by Blankj.
the class AppUtils method getAppVersionCode.
/**
* 获取App版本码
*
* @param context 上下文
* @param packageName 包名
* @return App版本码
*/
public static int getAppVersionCode(Context context, String packageName) {
if (StringUtils.isSpace(packageName))
return -1;
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return pi == null ? -1 : pi.versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return -1;
}
}
use of android.content.pm.PackageInfo in project AndroidUtilCode by Blankj.
the class AppUtils method getAppInfo.
/**
* 获取App信息
* <p>AppInfo(名称,图标,包名,版本号,版本Code,是否系统应用)</p>
*
* @param context 上下文
* @param packageName 包名
* @return 当前应用的AppInfo
*/
public static AppInfo getAppInfo(Context context, String packageName) {
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return getBean(pm, pi);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}
Aggregations