Reputation: 1250
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.
Upvotes: 4
Views: 2688
Reputation: 181
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.
Upvotes: 1
Reputation: 61
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+
Upvotes: 1
Reputation: 24039
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;
Upvotes: -1