Search in sources :

Example 31 with PackageInfo

use of android.content.pm.PackageInfo in project bee by orhanobut.

the class UiHandler method createInfoContent.

/**
   * It is called when the predefined information is created
   *
   * @return map which contains some predefined information
   */
private Map<String, String> createInfoContent() {
    PackageInfo packageInfo;
    Map<String, String> content = new LinkedHashMap<>();
    try {
        PackageManager packageManager = context.getPackageManager();
        packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        Log.d(TAG, "name not found");
        return content;
    }
    content.put("Package Name", packageInfo.packageName);
    content.put("Version Name", packageInfo.versionName);
    content.put("Version Code", "" + packageInfo.versionCode);
    content.put("First Install Time", new Date(packageInfo.firstInstallTime).toString());
    content.put("Update Time", new Date(packageInfo.lastUpdateTime).toString());
    content.put("Android Version", Build.VERSION.RELEASE);
    content.put("Display", Build.DISPLAY);
    content.put("Device Model", Build.MODEL);
    return content;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with PackageInfo

use of android.content.pm.PackageInfo in project superCleanMaster by joyoyao.

the class AppUtil method getVersionCode.

public static int getVersionCode(Context context) {
    try {
        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        int versionCode = info.versionCode;
        return versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) IOException(java.io.IOException)

Example 33 with PackageInfo

use of android.content.pm.PackageInfo in project superCleanMaster by joyoyao.

the class AppUtil method getRunningAppProcesses.

/**
     * 描述:获取运行的进程列表.
     *
     * @param context
     * @return
     */
public static List<AppProcessInfo> getRunningAppProcesses(Context context) {
    ActivityManager activityManager = null;
    List<AppProcessInfo> list = null;
    PackageManager packageManager = null;
    try {
        activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        packageManager = context.getApplicationContext().getPackageManager();
        list = new ArrayList<AppProcessInfo>();
        // 所有运行的进程
        List<RunningAppProcessInfo> appProcessList = activityManager.getRunningAppProcesses();
        ApplicationInfo appInfo = null;
        AppProcessInfo abAppProcessInfo = null;
        PackageInfo packageInfo = getPackageInfo(context);
        if (mProcessList != null) {
            mProcessList.clear();
        }
        mProcessList = getProcessRunningInfo();
        for (RunningAppProcessInfo appProcessInfo : appProcessList) {
            abAppProcessInfo = new AppProcessInfo(appProcessInfo.processName, appProcessInfo.pid, appProcessInfo.uid);
            appInfo = getApplicationInfo(context, appProcessInfo.processName);
            if (appInfo != null) {
                if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    abAppProcessInfo.isSystem = true;
                } else {
                    abAppProcessInfo.isSystem = false;
                }
                Drawable icon = appInfo.loadIcon(packageManager);
                String appName = appInfo.loadLabel(packageManager).toString();
                abAppProcessInfo.icon = icon;
                abAppProcessInfo.appName = appName;
            } else {
                // :服务的命名
                if (appProcessInfo.processName.indexOf(":") != -1) {
                    appInfo = getApplicationInfo(context, appProcessInfo.processName.split(":")[0]);
                    Drawable icon = appInfo.loadIcon(packageManager);
                    abAppProcessInfo.icon = icon;
                }
                abAppProcessInfo.isSystem = true;
                abAppProcessInfo.appName = appProcessInfo.processName;
            }
            /*
                 * AbPsRow psRow = getPsRow(appProcessInfo.processName);
				 * if(psRow!=null){ abAppProcessInfo.memory = psRow.mem; }
				 */
            ProcessInfo processInfo = getMemInfo(appProcessInfo.processName);
            abAppProcessInfo.memory = processInfo.memory;
            abAppProcessInfo.cpu = processInfo.cpu;
            abAppProcessInfo.status = processInfo.status;
            abAppProcessInfo.threadsCount = processInfo.threadsCount;
            list.add(abAppProcessInfo);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Drawable(android.graphics.drawable.Drawable) ProcessInfo(com.yzy.supercleanmaster.bean.ProcessInfo) AppProcessInfo(com.yzy.supercleanmaster.bean.AppProcessInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) AppProcessInfo(com.yzy.supercleanmaster.bean.AppProcessInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) IOException(java.io.IOException) PackageManager(android.content.pm.PackageManager) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo)

Example 34 with PackageInfo

use of android.content.pm.PackageInfo in project superCleanMaster by joyoyao.

the class AppUtil method getVersion.

public static String getVersion(Context context) {
    try {
        PackageManager manager = context.getPackageManager();
        PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
        String version = info.versionName;
        return version;
    } catch (Exception e) {
        e.printStackTrace();
        return "1.0";
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) IOException(java.io.IOException)

Example 35 with PackageInfo

use of android.content.pm.PackageInfo in project QLibrary by DragonsQC.

the class AppUtils method getPackageInfo.

/**
     * 获得当前APP PackageInfo 对象
     *
     * @return PackageInfo 对象
     */
public PackageInfo getPackageInfo(Context context) {
    PackageManager manager = context.getApplicationContext().getPackageManager();
    PackageInfo info = null;
    try {
        info = manager.getPackageInfo(context.getApplicationContext().getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return info;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1566 PackageManager (android.content.pm.PackageManager)702 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