Compare downloaded apk file version with installed one version programmaticaly - android

I wanted to know that is it possible to find version of an apk file that i've downloaded from the server?
i can retrieve the version of my app that is installed on device but i want to check installed app version on device with the downloaded apk file version.

You cannot easily get the version of the APK file you downloaded until you have installed it.
That being said, you can unzip the APK file (its just a zip file) and parse the AndroidManifest.xml to get the value of the version code.
Since the AndroidManifest.xml you extract is a binary file, you will need to write some code to parse it. It's not as simple as inspecting a plain text file.
Check out this post on how to parse the AndroidManifest which has been extracted from an APK.
How to parse the AndroidManifest.xml file inside an .apk package

PackageManager manager = this.getPackageManager();
PackageInfo info = manager.getPackageInfo("com.whatsapp", 0);
String packageName = info.packageName;
int versionCode = info.versionCode;
String versionName = info.versionName;
Replace com.whatsapp with your package name.

Related

How Can I remove an APK file using the package name?

Consider we have an APK file in an internal storage or external storage.How Can I remove an APK file using the package name and not with the file name? Is this possible in android?
Check this info from documentation:
You can use this method to get PackageInfo from your apk file then you could verify package name to do what you want.
Hope that it helps.
Reference: http://developer.android.com/reference/android/content/pm/PackageManager.html#getPackageArchiveInfo(java.lang.String,%20int)

how to get .apk file byte array from its packagename in AS3/AIR?

I want to know if it's possible to access a .apk file from an installed application on a device (android), via its package Name in as3/air?
Right now I have an ANE file which helps me to get packageName (ex: com.somesite.someApp or air.myApp), I want to copy the .apk file (its byteArray), is this possible in as3/air or is there any available ANE file to do this?

PhoneGap - Updating the apk file in Google Play says "Your APK's version code needs to be higher"

I am having a problem, when I try to update an APK production file in android, it says
"Your APK's version code needs to be higher than 19."
My app is built with phonegap and I have the following code in my config.xml .
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.rodriguezcab.release"
version = "20.0.1">
Though I have version = "20.0.1", it keeps saying "Your APK's version code needs to be higher than 19." Any solutions?
You can set this in config.xml (in the root of your cordova project). This is better than setting in 'platforms/android/AndroidManifest.xml' because platforms folder can be deleted.
In config.xml set this in the root (widget) node:
versionCode="20"
Note this changed since previous versions (don't you love that?) when it was:
android-versionCode="20"
Check platforms/android/AndroidManifest.xml
There you will see android:versionCode
This number needs to be incremented for new versions of the app. Don't get this confused with android:versionName that gets changed from the config.xml file when you do your build.

Parse Error - Installing apk programmatically

I am trying to install an apk file programmatically. I referred this site for doing it.
Now the apk file is downloaded from an url and placed in SDCard. When I try to install it on the device using Intent method,
It is popping up following error
Emulator:
"Parse Error - There is a problem parsing the package",
Logcat(W) : "Unable to read AndroidManifest.xml of /mnt/sdcard/download/myapp.apk",
Logcat(W) : "java.ioException: AndroidManifest.xml",
Logcat(W) : "Parse error when parsing manifest. Discontinuing installation".
Logcat(E) : "java.lang.SecurityException",
Logcat(E) : "java.lang.NullPointerException".
Note: 1) I was able to install the same .apk file using adb.
2) I changed this .apk file to .pdf format before sending it to Server Team and then they changed it back to .apk. I am adding this coz there might be chances for error due to format conversion.
Installation can give the specified error at least in following cases:
Name of the package is changed after signing: Use the exact name as
the signed package is (instead, adjust the name in Manifest)
Package is compiled against on higher API level: Correct the API
level in Manifest file
Package is executed from SD-card: Run (install) the apk -file
from phones memory OR use adb command to install it
Please check this code
private void installApk(){
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File("/sdcard/path"));
intent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(intent);}

Reading android MANIFEST.MF file

Is there a way to read META-INF\MANIFEST.MF file of the currently running application using Android API?
I want to read SHA1 for classes.dex file and use it as an encrpytion key to one of my assets.
I cannot use the signature for .apk file because everytime I create a new apk I need to re-encrpyte my asset and put in to apk file which requires re-signing the .apk and it becomes a chicken and egg problem.
I have found a way to do it. I opne the .apk file as a JarFile and then I can access individual files inside .apk. I believe this will only work for the .apk file that is running this code.
Here it is:
// Get Package Name
String packageName = ctx.getPackageName();
// Get classes.dex file signature
ApplicationInfo ai = ctx.getApplicationInfo();
String source = ai.sourceDir;
JarFile jar = new JarFile(source);
Manifest mf = jar.getManifest();
Map<String, Attributes> map = mf.getEntries();
Attributes a = map.get("classes.dex");
String sha1 = (String)a.getValue("SHA1-Digest");
Use following way to detect External Jar/SDK MANIFEST.MF Info. We could use this info for detecting Jar version etc. Use http://docs.oracle.com/javase/6/docs/api/java/util/jar/Manifest.html
public void getSDKInfo() {
Package package = Manifest.class.getPackage();
String specTitle = package.getSpecificationTitle();
String vendor = package.getSpecificationVendor();
String virsion = package.getSpecificationVersion();
}

Categories

Resources