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;
}
}
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;
}
}
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);
}
}
}
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;
}
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);
}
}
Aggregations