I have one non activity class, in this class I have several apk file path like /system/priv-app/TelephonyProvider/TelephonyProvider.apk, Now from this file path I have to retrieve package name of apk files.
Any suggestion will be appreciated. Thanks
Ok I got the answer:
PackageManager pm = mContext.getPackageManager();
PackageInfo info = pm.getPackageArchiveInfo(path, 0);
String pkgName = info.packageName
Thanks all, Actually after cleaning project it works
Related
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)
Is it possible to get package name of the installing application before app installed. i.e., While showing installer activity itself can we find?
Thanks.
We can get package name of application from .apk file using its filepath.
PackageInfo packageInfo = getPackageManager().getPackageArchiveInfo(filepath,PackageManager.GET_ACTIVITIES);
if(packageInfo != null) {
ApplicationInfo appInfo = packageInfo.applicationInfo;
String package_name= appInfo.packageName;
}
where filepath is a String containing filepath of the apk e.g. "/sdcard/xyz.apk".
Make sure you add READ_EXTERNAL_STORAGE uses permission in AndroidManifest.xml
I hope this helps.
I have a requirement to implement an equivalent of following java code in JNI C on android:
PackageManager pm = context.getPackageManager();
List<PackageInfo> packages = pm.getInstalledPackages(0);
for(PackageInfo packageInfo : packages) {
...
}
My question is how to get installed packages in JNI C. Is it even possible?
Thanks
Your best bet is to call PacakgeManager via JNI. There is no "C interface", you have to go through the system service. Installing a package does quite a few things, so just copying the APK to the right place is not enough.
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.
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();
}