use of android.content.pm.PackageManager in project atlas by alibaba.
the class DelegateClassLoader method getPackageVersion.
private static int getPackageVersion() {
PackageInfo packageInfo = null;
// 获取当前的版本号
try {
PackageManager packageManager = RuntimeVariables.androidApplication.getPackageManager();
packageInfo = packageManager.getPackageInfo(RuntimeVariables.androidApplication.getPackageName(), 0);
} catch (Exception e) {
// 不可能发生
packageInfo = new PackageInfo();
}
return packageInfo.versionCode;
}
use of android.content.pm.PackageManager in project atlas by alibaba.
the class PackageManagerDelegater method delegatepackageManager.
public static void delegatepackageManager(Context context) {
try {
mBaseContext = context;
PackageManager manager = mBaseContext.getPackageManager();
if (mProxyPm == null) {
Class ApplicationPackageManager = Class.forName("android.app.ApplicationPackageManager");
Field field = ApplicationPackageManager.getDeclaredField("mPM");
field.setAccessible(true);
Object rawPm = field.get(manager);
Class IPackageManagerClass = Class.forName("android.content.pm.IPackageManager");
if (rawPm != null) {
if (mPackageManagerProxyhandler == null) {
mPackageManagerProxyhandler = new PackageManagerProxyhandler(rawPm);
}
mProxyPm = Proxy.newProxyInstance(mBaseContext.getClassLoader(), new Class[] { IPackageManagerClass }, mPackageManagerProxyhandler);
}
field.set(manager, mProxyPm);
}
} catch (Throwable e) {
}
}
use of android.content.pm.PackageManager in project atlas by alibaba.
the class AtlasBridgeApplication method isUpdated.
public boolean isUpdated(Context context) {
PackageInfo packageInfo = null;
// 获取当前的版本号
try {
PackageManager packageManager = context.getPackageManager();
packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
} catch (Exception e) {
// 不可能发生
android.os.Process.killProcess(android.os.Process.myPid());
}
mInstalledVersionName = packageInfo.versionName;
// 检测之前的版本记录
SharedPreferences prefs = context.getSharedPreferences("atlas_configs", Context.MODE_PRIVATE);
int lastVersionCode = prefs.getInt("last_version_code", 0);
String lastVersionName = prefs.getString("last_version_name", "");
if (packageInfo.versionCode == lastVersionCode && TextUtils.equals(packageInfo.versionName, lastVersionName) && !needRollback()) {
return false;
}
return true;
}
use of android.content.pm.PackageManager in project Jota-Text-Editor-old by jiro-aqua.
the class ActivityPicker method putIntentItems.
/**
* Fill the given list with any activities matching the base {@link Intent}.
*/
protected void putIntentItems(Intent baseIntent, List<PickAdapter.Item> items) {
PackageManager packageManager = getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(baseIntent, 0);
Collections.sort(list, new ResolveInfo.DisplayNameComparator(packageManager));
final int listSize = list.size();
for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i);
items.add(new PickAdapter.Item(this, packageManager, resolveInfo));
}
}
use of android.content.pm.PackageManager in project Jota-Text-Editor-old by jiro-aqua.
the class DonateActivity method isDebuggable.
public boolean isDebuggable() {
PackageManager manager = getPackageManager();
ApplicationInfo appInfo = null;
try {
appInfo = manager.getApplicationInfo(getPackageName(), 0);
} catch (NameNotFoundException e) {
return false;
}
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) == ApplicationInfo.FLAG_DEBUGGABLE)
return true;
return false;
}
Aggregations