Code example for PackageManager

Methods: checkPermission

0
        if (pm == null) {
            return false; 
        } 
 
        try { 
            return pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
        } catch (RuntimeException e) {
            // To catch RuntimeException("Package manager has died") that can occur on some version of Android, 
            // when the remote PackageManager is unavailable. I suspect this sometimes occurs when the App is being reinstalled. 
            return false; 
        } 
    } 
 
    /** 
     * @return PackageInfo for the current application or null if the PackageManager could not be contacted. 
     */ 
    public PackageInfo getPackageInfo() {
        final PackageManager pm = context.getPackageManager();
        if (pm == null) {
            return null; 
        }