Search in sources :

Example 96 with PackageInfo

use of android.content.pm.PackageInfo in project UltimateAndroid by cymcsg.

the class BasicUtils method getVersionName.

/**
     * get the version name which defines in AndroidManifest.xml
     *
     * @param context
     * @return
     */
public static String getVersionName(Context context) {
    String version = "";
    try {
        // get packagemanager
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()--your current package name,0 means get package info
        PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        version = packInfo.versionName;
    } catch (Exception e) {
        e.printStackTrace();
        Logs.e(e.getMessage());
    } finally {
        return version;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 97 with PackageInfo

use of android.content.pm.PackageInfo in project UltimateAndroid by cymcsg.

the class BasicUtils method getVersionCode.

/**
     * get the version code which defines in AndroidManifest.xml
     *
     * @param context
     * @return
     */
public static int getVersionCode(Context context) {
    int version = 0;
    try {
        // get packagemanager
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()--your current package name,0 means get package info
        PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        version = packInfo.versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        Logs.e(e.getMessage());
    } finally {
        return version;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 98 with PackageInfo

use of android.content.pm.PackageInfo in project UltimateAndroid by cymcsg.

the class CrashHandler method collectDeviceInfo.

/**
     * Collect Device info
     *
     * @param ctx
     */
public void collectDeviceInfo(Context ctx) {
    try {
        PackageManager pm = ctx.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_ACTIVITIES);
        if (pi != null) {
            String versionName = pi.versionName == null ? "null" : pi.versionName;
            String versionCode = pi.versionCode + "";
            infos.put("versionName", versionName);
            infos.put("versionCode", versionCode);
        }
    } catch (NameNotFoundException e) {
        Logs.e("an error occured when collect package info", e);
    }
    Field[] fields = Build.class.getDeclaredFields();
    for (Field field : fields) {
        try {
            field.setAccessible(true);
            infos.put(field.getName(), field.get(null).toString());
            Logs.d(field.getName() + " : " + field.get(null));
        } catch (Exception e) {
            Logs.e("an error occured when collect crash info", e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 99 with PackageInfo

use of android.content.pm.PackageInfo in project acra by ACRA.

the class ApplicationStartupProcessor method getAppVersion.

/**
     * @return app version or 0 if PackageInfo was not available.
     */
private int getAppVersion() {
    final PackageManagerWrapper packageManagerWrapper = new PackageManagerWrapper(context);
    final PackageInfo packageInfo = packageManagerWrapper.getPackageInfo();
    return (packageInfo == null) ? 0 : packageInfo.versionCode;
}
Also used : PackageInfo(android.content.pm.PackageInfo)

Example 100 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method enforceOwnerRights.

// Enforcing that callingUid is owning pkg on userId
private void enforceOwnerRights(String pkg, int callingUid) {
    // The system owns everything.
    if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) {
        return;
    }
    int callingUserId = UserHandle.getUserId(callingUid);
    PackageInfo pi = getPackageInfo(pkg, 0, callingUserId);
    if (pi == null) {
        throw new IllegalArgumentException("Unknown package " + pkg + " on user " + callingUserId);
    }
    if (!UserHandle.isSameApp(pi.applicationInfo.uid, callingUid)) {
        throw new SecurityException("Calling uid " + callingUid + " does not own package " + pkg);
    }
}
Also used : 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