Question

Good day!
I tried this code :

PackageInfo info = mContext.getPackageManager().getPackageArchiveInfo(absolute_apk_name, PackageManager.GET_SIGNATURES);
        if (info != null)
        {
            Signature[] sig = info.signatures;
            if (sig != null)
                sigstring = new String(sig[0].toChars());
        }

But info.signatures == null, and I do not have any idea "why?"
File in absolute_apk_name exists, I checked Android 2.1

UPD:

absolute_apk_name = "/data/data/ru.UseIT.SimpleFormsLauncher/files/SimpleFormsGeneral.apk"  

apk was created with flags Context.MODE_WORLD_READABLE|Context.MODE_WORLD_WRITEABLE

But if exec this code

Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(Uri.fromFile(new File(absolute_apk_name )), "application/vnd.android.package-archive");
        mContext.startActivity(intent);

It was installed.

Was it helpful?

Solution

I checked the Android source, and it turns out that PackageManager#getPackageArchiveInfo(String, int) does not include signatures if Android version is 2.3.7 and less.

Please look below links.

http://tools.oesf.biz/android-2.3.7_r1.0/xref/frameworks/base/core/java/android/content/pm/PackageManager.java#1891

http://tools.oesf.biz/android-4.0.3_r1.0/xref/frameworks/base/core/java/android/content/pm/PackageManager.java#2121

OTHER TIPS

it is an android system bug see this https://code.google.com/p/android/issues/detail?id=9151#c8 this bug has fixed on 4.0+

I'm not quite sure what your trying to achieve, but using the absolute apk name/path is incorrect, you need the packagename. I've been able to get the signatures using the following, just replace "com.android.chrome" with the package name of the app you want.

final PackageInfo pkgInfo = packageManager.getPackageInfo(
                    "com.android.chrome", PackageManager.GET_SIGNATURES);
final Signature[] signatures = pkgInfo.signatures;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top