Search in sources :

Example 86 with PackageInfo

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);
            }
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) ProviderInfo(android.content.pm.ProviderInfo) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent)

Example 87 with PackageInfo

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;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 88 with PackageInfo

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;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) SuppressLint(android.annotation.SuppressLint)

Example 89 with PackageInfo

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;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 90 with PackageInfo

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;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1567 PackageManager (android.content.pm.PackageManager)703 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)327 ApplicationInfo (android.content.pm.ApplicationInfo)217 Test (org.junit.Test)193 RemoteException (android.os.RemoteException)179 ArrayList (java.util.ArrayList)166 Intent (android.content.Intent)126 IOException (java.io.IOException)121 Context (android.content.Context)81 IPackageManager (android.content.pm.IPackageManager)65 ResolveInfo (android.content.pm.ResolveInfo)65 File (java.io.File)62 SuppressLint (android.annotation.SuppressLint)58 ComponentName (android.content.ComponentName)57 ActivityInfo (android.content.pm.ActivityInfo)57 View (android.view.View)57 TextView (android.widget.TextView)54 Signature (android.content.pm.Signature)51 OverlayInfo (android.content.om.OverlayInfo)42