Java 类android.content.pm.PackageInfo 实例源码

项目:lineagex86    文件:AppNotificationSettings.java   
private static PackageInfo findPackageInfo(PackageManager pm, String pkg, int uid) {
    final String[] packages = pm.getPackagesForUid(uid);
    if (packages != null && pkg != null) {
        final int N = packages.length;
        for (int i = 0; i < N; i++) {
            final String p = packages[i];
            if (pkg.equals(p)) {
                try {
                    return pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
                } catch (NameNotFoundException e) {
                    Log.w(TAG, "Failed to load package " + pkg, e);
                }
            }
        }
    }
    return null;
}
项目:TIIEHenry-Android-SDK    文件:AppUtils.java   
/**
 * 获得APP的名称
 *
 * @param context
 * @return
 */
public static String getAppName(Context context) {
    if (context == null) {
        return null;
    }
    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(
                context.getPackageName(), 0);
        int labelRes = packageInfo.applicationInfo.labelRes;
        String appName = context.getResources().getString(labelRes);
        return appName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
项目:Android-Code-Demos    文件:CrashHandler.java   
@SuppressWarnings("deprecation")
private void dumpPhoneInfo(PrintWriter pw) throws PackageManager.NameNotFoundException {
    PackageManager pm = mContext.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(),
            PackageManager.GET_ACTIVITIES);
    pw.print("App Version: ");
    pw.print(pi.versionName);
    pw.print('_');
    pw.println(pi.versionCode);

    /* Android 版本号 */
    pw.print("OS Version: ");
    pw.print(Build.VERSION.RELEASE);
    pw.print('_');
    pw.println(SDK_INT);

    /* 手机制造商 */
    pw.print("Vendor: ");
    pw.println(Build.MODEL);

    /* CPU 架构 */
    pw.print("CPU ABI: ");
    pw.println(Build.CPU_ABI);
}
项目:AndroidDvbDriver    文件:ExceptionDialog.java   
private String getConstants() {
    StringBuilder res = new StringBuilder();

    res.append("Last Device: ").append(lastDeviceDebugString).append('\n');
    res.append("Build.MANUFACTURER: ").append(Build.MANUFACTURER).append('\n');
    res.append("Build.MODEL: ").append(Build.MODEL).append('\n');
    res.append("Build.PRODUCT: ").append(Build.PRODUCT).append('\n');
    res.append("Build.VERSION.SDK_INT: ").append(Build.VERSION.SDK_INT).append('\n');
    res.append("Build.VERSION.RELEASE: ").append(Build.VERSION.RELEASE).append('\n');

    try {
        PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
        res.append("Driver versionName: ").append(packageInfo.versionName).append('\n');
        res.append("Driver versionCode: ").append(packageInfo.versionCode).append('\n');
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    return res.toString();
}
项目:permission-bitte    文件:PermissionBitteImpl.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @NonNull
static String[] neededPermissions(Context context) {
    PackageInfo info = null;
    try {
        info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
    } catch (PackageManager.NameNotFoundException e) { /* */ }
    List<String> needed = new ArrayList<>();
    if (info != null &&
        info.requestedPermissions != null &&
        info.requestedPermissionsFlags != null) {
        for (int i = 0; i < info.requestedPermissions.length; i++) {
            int flags = info.requestedPermissionsFlags[i];
            if ((flags & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) {
                needed.add(info.requestedPermissions[i]);
            }
        }
    }
    return needed.toArray(new String[needed.size()]);
}
项目:Nird2    文件:ScreenFilterMonitorImpl.java   
private boolean isOverlayApp(PackageInfo packageInfo) {
    int mask = FLAG_SYSTEM | FLAG_UPDATED_SYSTEM_APP;
    // Ignore system apps
    if ((packageInfo.applicationInfo.flags & mask) != 0) {
        return false;
    }
    // Ignore Play Services, it's effectively a system app
    if (isPlayServices(packageInfo.packageName)) {
        return false;
    }
    // Get permissions
    String[] requestedPermissions = packageInfo.requestedPermissions;
    if (requestedPermissions != null) {
        for (String requestedPermission : requestedPermissions) {
            if (requestedPermission.equals(SYSTEM_ALERT_WINDOW)) {
                return true;
            }
        }
    }
    return false;
}
项目:DUnit    文件:DUnitSimpleListActivity.java   
protected void setActionBarTitle(){
    if (isRootPage()){
        String pkgName = getPackageName();
        try {
            PackageInfo pkgInfo = getPackageManager().getPackageInfo(pkgName,0);
            CharSequence appLabel = getPackageManager().getApplicationLabel(pkgInfo.applicationInfo);
            getSupportActionBar().setTitle(appLabel.toString());
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return;
    }
    Class<? extends DUnitGroupInterface> currentGroup = getCurrentGroup();
    ArrayList<DUnitGroupModel> groupModels = DUnitManager.getInstance().getUnitGroupModels();
    for (DUnitGroupModel groupModel: groupModels) {
        if (groupModel.getOriginal() == currentGroup){
            getSupportActionBar().setTitle(groupModel.getName());
            return;
        }
    }
}
项目:Programmers    文件:IntentUtils.java   
public static void startShareApp(Activity activity) {
    try {
        String packageName = activity.getPackageName();
        PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(packageName, 0);
        String dir = packageInfo.applicationInfo.sourceDir;
        File tempFile = new File(dir);

        Intent i = new Intent();
        i.setAction(Intent.ACTION_SEND);
        i.setDataAndType(Uri.fromFile(tempFile), "application/vnd.android.package-archive");
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tempFile));

        // Testing...
        //Only use bluetooth to share the app
        i.setPackage("com.android.bluetooth");
        activity.startActivity(i);
    } catch (Exception e) {
        showLog("SHAREAPP: ", e.getMessage());
    }
}
项目:TPlayer    文件:AppTarget.java   
private AppTarget(Context context) {
    mContext = context;
    mSharedPreferences = context.getSharedPreferences("va_settings", Context.MODE_MULTI_PROCESS);
    // 从系统已安装的apk中安装插件,默认为false
    fromSystem = mSharedPreferences.getBoolean("fromSystem", false);
    firstInstall = mSharedPreferences.getBoolean("install", false);
    mApkFile = new File(Environment.getExternalStorageDirectory(), "debug.apk").getAbsolutePath();
    mUpdateFile = mApkFile;
    if (!firstInstall) {
        PackageInfo packageInfo = PackageUtils.getPackageInfo(context, PKG);
        // 如果从系统中查找该包名存在,说明系统中已安装过此apk, 则可以从系统中加载此插件.
        if (packageInfo != null) {
            fromSystem = true;
            mApkFile = packageInfo.applicationInfo.publicSourceDir;
        }
    }
}
项目:container    文件:GetInstalledPackages.java   
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    int flags = (int) args[0];
    int userId = VUserHandle.myUserId();
    List<PackageInfo> packageInfos;
    if (isAppProcess()) {
        packageInfos = new ArrayList<PackageInfo>(VirtualCore.get().getAppCount());
    } else {
        packageInfos = VirtualCore.get().getUnHookPackageManager().getInstalledPackages(flags);
    }
    packageInfos.addAll(VPackageManager.get().getInstalledPackages(flags, userId));
    if (ParceledListSliceCompat.isReturnParceledListSlice(method)) {
        return ParceledListSliceCompat.create(packageInfos);
    } else {
        return packageInfos;
    }
}
项目:Nird2    文件:ScreenFilterMonitorImpl.java   
private boolean isPlayServices(String pkg) {
    if (!PLAY_SERVICES_PACKAGE.equals(pkg)) return false;
    try {
        PackageInfo sigs = pm.getPackageInfo(pkg, GET_SIGNATURES);
        // The genuine Play Services app should have a single signature
        Signature[] signatures = sigs.signatures;
        if (signatures == null || signatures.length != 1) return false;
        // Extract the public key from the signature
        CertificateFactory certFactory =
                CertificateFactory.getInstance("X509");
        byte[] signatureBytes = signatures[0].toByteArray();
        InputStream in = new ByteArrayInputStream(signatureBytes);
        X509Certificate cert =
                (X509Certificate) certFactory.generateCertificate(in);
        byte[] publicKeyBytes = cert.getPublicKey().getEncoded();
        String publicKey = StringUtils.toHexString(publicKeyBytes);
        return PLAY_SERVICES_PUBLIC_KEY.equals(publicKey);
    } catch (NameNotFoundException | CertificateException e) {
        if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
        return false;
    }
}
项目:DizzyPassword    文件:MyApplication.java   
/**
 * 根据包名打开第三方应用
 *
 * @param context
 * @param packageName
 * @throws PackageManager.NameNotFoundException
 */
public static void openAppByPackageName(Context context, String packageName) throws PackageManager.NameNotFoundException {
    PackageInfo pi;
    try {
        pi = MyApplication.getContext().getPackageManager().getPackageInfo(packageName, 0);
        Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
        resolveIntent.setPackage(pi.packageName);
        PackageManager pManager = MyApplication.getContext().getPackageManager();
        List<ResolveInfo> apps = pManager.queryIntentActivities(resolveIntent, 0);
        ResolveInfo ri = apps.iterator().next();
        if (ri != null) {
            packageName = ri.activityInfo.packageName;
            String className = ri.activityInfo.name;
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);//重点是加这个
            ComponentName cn = new ComponentName(packageName, className);
            intent.setComponent(cn);
            context.startActivity(intent);
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}
项目:ClassLoader    文件:MainActivity.java   
public String getApkInfo(String fileName) {
    try {
        String dexPath = null;
        if (getExternalFilesDir(null) != null) {
            dexPath = new File(getExternalFilesDir(null), fileName).getAbsolutePath();
        } else if (getFilesDir() != null) {
            dexPath = new File(getFilesDir(), fileName).getAbsolutePath();
        }

        PackageManager pm = getPackageManager();
        PackageInfo info = pm.getPackageArchiveInfo(dexPath, 0);

        StringBuilder sb = new StringBuilder();
        sb.append("\n*** Apk info ***\n");
        sb.append("versionCode:" + info.versionCode);
        sb.append("\nversionName:" + info.versionName);
        sb.append("\n*** Apk info ***\n");

        return sb.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return e.toString();
    }
}
项目:TPlayer    文件:PackageParserCompat.java   
public static PackageInfo generatePackageInfo(Package p, int flags, long firstInstallTime, long lastUpdateTime) {
    if (API_LEVEL >= M) {
        return PackageParserMarshmallow.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                null, sUserState);
    } else if (API_LEVEL >= LOLLIPOP) {
        if (PackageParserLollipop22.generatePackageInfo != null) {
            return PackageParserLollipop22.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                    null, sUserState);
        } else {
            return PackageParserLollipop.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                    null, sUserState);
        }
    } else if (API_LEVEL >= JELLY_BEAN_MR1) {
        return PackageParserJellyBean17.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                null, sUserState);
    } else if (API_LEVEL >= JELLY_BEAN) {
        return PackageParserJellyBean.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                null);
    } else {
        return mirror.android.content.pm.PackageParser.generatePackageInfo.call(p, GIDS, flags, firstInstallTime,
                lastUpdateTime);
    }
}
项目:FontProvider    文件:FontProviderClient.java   
/**
 * Check if Font Provider app is available.
 *
 * @param context Context
 * @return code
 *
 * @see FontProviderAvailability#OK
 * @see FontProviderAvailability#NOT_INSTALLED
 * @see FontProviderAvailability#DISABLED
 * @see FontProviderAvailability#VERSION_TOO_LOW
 */
public static @FontProviderAvailability int checkAvailability(Context context) {
    PackageInfo pi = null;
    try {
        pi = context.getPackageManager().getPackageInfo(PACKAGE, 0);
    } catch (PackageManager.NameNotFoundException ignored) {
    }

    if (pi == null) {
        return NOT_INSTALLED;
    }

    if (!pi.applicationInfo.enabled) {
        return DISABLED;
    }

    if (pi.versionCode < MIN_VERSION) {
        return VERSION_TOO_LOW;
    }

    return OK;
}
项目:Bigbang    文件:CropImage.java   
/**
 * Check if the app requests a specific permission in the manifest.
 *
 * @param permissionName the permission to check
 * @return true - the permission in requested in manifest, false - not.
 */
public static boolean hasPermissionInManifest(@NonNull Context context, @NonNull String permissionName) {
    String packageName = context.getPackageName();
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
        final String[] declaredPermisisons = packageInfo.requestedPermissions;
        if (declaredPermisisons != null && declaredPermisisons.length > 0) {
            for (String p : declaredPermisisons) {
                if (p.equalsIgnoreCase(permissionName)) {
                    return true;
                }
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
    }
    return false;
}
项目:FakeWeather    文件:AppExceptionHandler.java   
/**
 * 获取一些简单的信息,软件版本,手机版本,型号等信息存放在HashMap中
 *
 * @param context
 * @return
 */
private HashMap<String, String> obtainSimpleInfo(Context context) {
    HashMap<String, String> map = new HashMap<String, String>();
    PackageManager mPackageManager = context.getPackageManager();
    PackageInfo mPackageInfo = null;
    try {
        mPackageInfo = mPackageManager.getPackageInfo(
                context.getPackageName(), PackageManager.GET_ACTIVITIES);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    map.put("versionName", mPackageInfo.versionName);
    map.put("versionCode", "" + mPackageInfo.versionCode);

    map.put("MODEL", "" + Build.MODEL);
    map.put("SDK_INT", "" + Build.VERSION.SDK_INT);
    map.put("PRODUCT", "" + Build.PRODUCT);

    return map;
}
项目:RetroMusicPlayer    文件:PackageValidator.java   
/**
 * @return true if the installed package signature matches the platform signature.
 */
private boolean isPlatformSigned(Context context, String pkgName) {
    PackageInfo platformPackageInfo = getPackageInfo(context, "android");

    // Should never happen.
    if (platformPackageInfo == null || platformPackageInfo.signatures == null
            || platformPackageInfo.signatures.length == 0) {
        return false;
    }

    PackageInfo clientPackageInfo = getPackageInfo(context, pkgName);

    return (clientPackageInfo != null && clientPackageInfo.signatures != null
            && clientPackageInfo.signatures.length > 0 &&
            platformPackageInfo.signatures[0].equals(clientPackageInfo.signatures[0]));
}
项目:Liteframework    文件:PackageUtil.java   
public static int getAppVersionCode(Context context) {
    if (context != null) {
        PackageManager pm = context.getPackageManager();
        if (pm != null) {
            PackageInfo pi;
            try {
                pi = pm.getPackageInfo(context.getPackageName(), 0);
                if (pi != null) {
                    return pi.versionCode;
                }
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return -1;
}
项目:Android-Code-Demos    文件:CrashHandler.java   
@SuppressWarnings("deprecation")
private void dumpPhoneInfo(PrintWriter pw) throws PackageManager.NameNotFoundException {
    PackageManager pm = mContext.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(),
            PackageManager.GET_ACTIVITIES);
    pw.print("App Version: ");
    pw.print(pi.versionName);
    pw.print('_');
    pw.println(pi.versionCode);

    /* Android 版本号 */
    pw.print("OS Version: ");
    pw.print(Build.VERSION.RELEASE);
    pw.print('_');
    pw.println(SDK_INT);

    /* 手机制造商 */
    pw.print("Vendor: ");
    pw.println(Build.MODEL);

    /* CPU 架构 */
    pw.print("CPU ABI: ");
    pw.println(Build.CPU_ABI);
}
项目:ZeusHotfix    文件:PackageManagerInvocation.java   
@Override
public Object invoke(Object paramObject, Method paramMethod,
                     Object[] paramArrayOfObject) {
    Object localObject = null;
    try {
        localObject = paramMethod.invoke(mPackageManager, paramArrayOfObject);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if ((paramMethod.getName().equals("getPackageInfo"))
            && (paramArrayOfObject[0].equals(mContext.getPackageName()))) {

        PackageInfo localPackageInfo = (PackageInfo) localObject;
        if (localPackageInfo != null) {
            localPackageInfo.versionCode = mVersionCode;
            localPackageInfo.versionName = mVersionName;
            if (localPackageInfo.applicationInfo != null) {
                localPackageInfo.applicationInfo.nativeLibraryDir = nativeLibraryDir;
                localPackageInfo.applicationInfo.publicSourceDir = publicSourceDir;
                localPackageInfo.applicationInfo.sourceDir = sourceDir;
            }
        }
    }
    return localObject;
}
项目:easyfilemanager    文件:IconUtils.java   
public static Drawable loadPackagePathIcon(Context context, String path, String mimeType){
    int icon =  sMimeIcons.get(mimeType);
     if (path != null) {
         final PackageManager pm = context.getPackageManager();
try {
    final PackageInfo packageInfo = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
    if (packageInfo != null) {
        packageInfo.applicationInfo.sourceDir = packageInfo.applicationInfo.publicSourceDir = path;
        // know issue with nine patch image instead of drawable
        return pm.getApplicationIcon(packageInfo.applicationInfo);
    }
} catch (Exception e) {
    return ContextCompat.getDrawable(context, icon);
}
     } else {
         return ContextCompat.getDrawable(context, icon);
     }
     return null;
 }
项目:Hotspot-master-devp    文件:AppUtils.java   
/**
 *  判断当前应用是否是顶栈
 * @param context
 * @return
 */
public static boolean isAppOnForeground(Context context){
    PackageInfo info = null;
    try{
    info=context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    String curPackage=info.packageName;
    ActivityManager mActivityManager = ((ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE));
    List<RunningTaskInfo> tasksInfo = mActivityManager.getRunningTasks(1);
    if(tasksInfo!=null && tasksInfo.size()>0){
        if (!TextUtils.isEmpty(curPackage) && curPackage.equals(tasksInfo.get(0).topActivity.getPackageName())) {
            /**当前应用是顶栈*/
            return true;
        } 

    }
    }catch(Exception ex){
        LogUtils.e(ex.toString());
    }
    return false;
}
项目:MyTvLauncher    文件:Tools.java   
public static PackageInfo getAPKVersionInfo(Context context,
                                            String packageName) {
    PackageManager packageManager = context.getPackageManager();
    PackageInfo packInfo = null;
    try {
        packInfo = packageManager.getPackageInfo(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return packInfo;
}
项目:Cluttr    文件:CropImage.java   
/**
 * Check if the app requests a specific permission in the manifest.
 *
 * @param permissionName the permission to check
 * @return true - the permission in requested in manifest, false - not.
 */
public static boolean hasPermissionInManifest(@NonNull Context context, @NonNull String permissionName) {
    String packageName = context.getPackageName();
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
        final String[] declaredPermisisons = packageInfo.requestedPermissions;
        if (declaredPermisisons != null && declaredPermisisons.length > 0) {
            for (String p : declaredPermisisons) {
                if (p.equalsIgnoreCase(permissionName)) {
                    return true;
                }
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
    }
    return false;
}
项目:KUtils-master    文件:Utils.java   
/**
 * 获取系统中所有的应用
 *
 * @param context 上下文
 * @return 应用信息List
 */
public static List<PackageInfo> getAllApps(Context context) {

    List<PackageInfo> apps = new ArrayList<PackageInfo>();
    PackageManager pManager = context.getPackageManager();
    List<PackageInfo> paklist = pManager.getInstalledPackages(0);
    for (int i = 0; i < paklist.size(); i++) {
        PackageInfo pak = paklist.get(i);
        if ((pak.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <=
                0) {
            // customs applications
            apps.add(pak);
        }
    }
    return apps;
}
项目:letv    文件:IApkManagerImpl.java   
private void saveSignatures(PackageInfo pkgInfo) {
    JLog.log("plugin", "保存签名信息: " + pkgInfo.signatures);
    if (pkgInfo != null && pkgInfo.signatures != null) {
        int i = 0;
        Signature[] signatureArr = pkgInfo.signatures;
        int length = signatureArr.length;
        int i2 = 0;
        while (i2 < length) {
            Signature signature = signatureArr[i2];
            File file = new File(PluginDirHelper.getPluginSignatureFile(this.mContext, pkgInfo.packageName, i));
            try {
                Utils.writeToFile(file, signature.toByteArray());
                JLog.log("plugin", "保存签名信息 包名=" + pkgInfo.packageName + ",i=" + i + ", 签名md5=" + Utils.md5(signature.toByteArray()));
                i++;
                i2++;
            } catch (Exception e) {
                JLog.log("plugin", "保存签名信息失败 e=" + e.getMessage());
                file.delete();
                Utils.deleteDir(PluginDirHelper.getPluginSignatureDir(this.mContext, pkgInfo.packageName));
                return;
            }
        }
    }
}
项目:browser    文件:MainApp.java   
/**
 * 获取应用程序版本名称
 * @return
 */
public String getVersion() {
    String version = "0.0.0";
    if(context == null) {
        return version;
    }
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(
                getPackageName(), 0);
        version = packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    return version;
}
项目:Brevent    文件:BreventActivity.java   
public boolean hasGms() {
    PackageManager packageManager = getPackageManager();
    PackageInfo packageInfo;
    try {
        packageInfo = packageManager.getPackageInfo(GMS, 0);
        if (!packageInfo.applicationInfo.enabled) {
            return false;
        }
    } catch (PackageManager.NameNotFoundException e) { // NOSONAR
        // do nothing
        return false;
    }

    SharedPreferences preferences = getSharedPreferences("signature", Context.MODE_PRIVATE);
    long lastUpdate = preferences.getLong(GMS_LAST_UPDATE, 0);
    if (preferences.contains(GMS_VALID) && packageInfo.lastUpdateTime == lastUpdate) {
        return preferences.getBoolean(GMS_VALID, false);
    }

    boolean valid = checkGms(packageInfo.applicationInfo.sourceDir);
    preferences.edit()
            .putBoolean(GMS_VALID, valid)
            .putLong(GMS_LAST_UPDATE, packageInfo.lastUpdateTime)
            .apply();
    return valid;
}
项目:TPlayer    文件:NotificationCompatCompatV21.java   
private boolean resolveRemoteViews(Context appContext, String packageName, Notification notification) {
    if (notification == null) {
        return false;
    }
    String sourcePath = null;
    PackageInfo packageInfo = getPackageInfo(packageName);
    ApplicationInfo host = getHostContext().getApplicationInfo();
    if (packageInfo != null) {
        sourcePath = packageInfo.applicationInfo.sourceDir;
    }
    if (TextUtils.isEmpty(sourcePath)) {
        sourcePath = getPackageResourcePath(packageName).getAbsolutePath();
    }

    //Fix RemoteViews
    getNotificationFixer().fixNotificationRemoteViews(appContext, notification);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        getNotificationFixer().fixIcon(notification.getSmallIcon(), appContext, packageInfo != null);
        getNotificationFixer().fixIcon(notification.getLargeIcon(), appContext, packageInfo != null);
    } else {
        getNotificationFixer().fixIconImage(appContext.getResources(), notification.contentView, false, notification);
    }
    notification.icon = host.icon;

    ApplicationInfo proxyApplicationInfo = new ApplicationInfo(host);

    proxyApplicationInfo.packageName = packageName;
    proxyApplicationInfo.publicSourceDir = sourcePath;
    proxyApplicationInfo.sourceDir = sourcePath;

    fixApplicationInfo(notification.tickerView, proxyApplicationInfo);
    fixApplicationInfo(notification.contentView, proxyApplicationInfo);
    fixApplicationInfo(notification.bigContentView, proxyApplicationInfo);
    fixApplicationInfo(notification.headsUpContentView, proxyApplicationInfo);
    Bundle bundle = Reflect.on(notification).get("extras");
    if (bundle != null) {
        bundle.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, proxyApplicationInfo);
    }
    return true;
}
项目:jiansan-java    文件:App.java   
/**
 * 获取当前应用的版本号
 *
 * @return 版本号
 */
public String getVersionName() {
    PackageManager pm = getPackageManager();
    // 第一个参数:应用程序的包名
    // 第二个参数:指定信息的标签,0表示获取基础信息,比如包名、版本号。要想获取权限等信息必须要通过标签指定。
    try {
        PackageInfo info = pm.getPackageInfo(getPackageName(), 0);
        return info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return "";
}
项目:AOSP-Kayboard-7.1.2    文件:ApplicationUtils.java   
/**
 * A utility method to get the application's PackageInfo.versionName
 * @return the application's PackageInfo.versionName
 */
public static String getVersionName(final Context context) {
    try {
        if (context == null) {
            return "";
        }
        final String packageName = context.getPackageName();
        final PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        return info.versionName;
    } catch (final NameNotFoundException e) {
        Log.e(TAG, "Could not find version info.", e);
    }
    return "";
}
项目:amap    文件:SystemUtils.java   
/**
 * 获取版本名称
 * @param context 上下文
 * @return 版本名称
 */
public static String getVersionName(Context context){
    //获取包管理器
    PackageManager pm = context.getPackageManager();
    //获取包信息
    try {
        PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(),0);
    //返回版本号
        return packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
项目:freehkkai-android    文件:Util.java   
public static String getCurrentVersionName(Context c) {
    try {
        PackageInfo pInfo = c.getPackageManager().getPackageInfo(
                c.getPackageName(), 0);
        return pInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        return "NA";
    }
}
项目:AndroidDonate    文件:AlipayDonate.java   
/**
 * 获取支付宝客户端版本名称,作用不大
 * @param context Context
 * @return 版本名称
 */
public static String getAlipayClientVersion(Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo info = pm.getPackageInfo(ALIPAY_PACKAGE_NAME, 0);
        return info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
项目:jackknife    文件:ApkUtils.java   
public static PackageInfo getPackageInfo(Context context, String packageName) {
    PackageManager packageManager = context.getPackageManager();
    try {
        return packageManager.getPackageInfo(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
项目:boohee_v5.6    文件:i.java   
private static a a(Context context, String str) {
    for (PackageInfo packageInfo : context.getPackageManager().getInstalledPackages(64)) {
        if (packageInfo.packageName.equals(str)) {
            a aVar = new a();
            aVar.a = packageInfo.signatures[0].toByteArray();
            aVar.b = packageInfo.versionCode;
            return aVar;
        }
    }
    return null;
}
项目:letv    文件:IApkManagerImpl.java   
private Signature[] getSignature(String pkg, PackageManager pm) throws RemoteException, NameNotFoundException {
    PackageInfo info = getPackageInfo(pkg, 64);
    if (info == null) {
        info = pm.getPackageInfo(pkg, 64);
    }
    if (info != null) {
        return info.signatures;
    }
    throw new NameNotFoundException();
}
项目:1946    文件:GcmPush.java   
/**
 * @return Application's version code from the {@code PackageManager}.
 */
private static int getAppVersion(Context context) 
{
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (NameNotFoundException e) {
        // should never happen
        throw new RuntimeException("Could not get package name: " + e);
    }
}
项目:q-mail    文件:Accounts.java   
/**
 * Get current version number.
 *
 * @return String version
 */
private String getVersionNumber() {
    String version = "?";
    try {
        PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
        version = pi.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        //Log.e(TAG, "Package name not found", e);
    }
    return version;
}