Search in sources :

Example 91 with PackageManager

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

Example 92 with PackageManager

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) {
    }
}
Also used : Field(java.lang.reflect.Field) PackageManager(android.content.pm.PackageManager)

Example 93 with PackageManager

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

Example 94 with PackageManager

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

Example 95 with PackageManager

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

Aggregations

PackageManager (android.content.pm.PackageManager)1429 Intent (android.content.Intent)483 ResolveInfo (android.content.pm.ResolveInfo)449 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)345 ApplicationInfo (android.content.pm.ApplicationInfo)249 PackageInfo (android.content.pm.PackageInfo)248 ComponentName (android.content.ComponentName)239 ArrayList (java.util.ArrayList)156 ActivityInfo (android.content.pm.ActivityInfo)135 IOException (java.io.IOException)126 RemoteException (android.os.RemoteException)105 IPackageManager (android.content.pm.IPackageManager)93 Drawable (android.graphics.drawable.Drawable)93 Resources (android.content.res.Resources)90 PendingIntent (android.app.PendingIntent)71 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)63 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)53 ServiceInfo (android.content.pm.ServiceInfo)46