返回顶部

收藏

获取apk文件的签名信息(未安装, 只是一个apk文件)

更多
    /** 
     * get signature of an apk file 
     * this method will execute quit a long time, so it is suitable to call it in sub thread 
     * @param context 
     * @param apkFilePath 
     * @return signature , null if there is no signature , or apkFilePath is wrong 
     */  
    public static String getSignatureOfApk(Context context, String apkFilePath){  
        Log.i(TAG, "SignatureUtils.getSignatureOfApk");  

        if (TextUtils.isEmpty(apkFilePath)) return null;  

        PackageManager pm = context.getPackageManager();  

        PackageInfo pi = pm.getPackageArchiveInfo(apkFilePath, PackageManager.GET_SIGNATURES);  
        Signature[] signatures = pi.signatures;  

        if(signatures != null && signatures.length > 0){  

            String signature =  signatures[0].toCharsString();  
            Log.i(TAG, "Signature of " + apkFilePath + " is : " + signature);  

            return  signature;  
        }  

        return null;  
    }  

标签:java

收藏

0人收藏

支持

0

反对

0

发表评论