I am developing an app which will contain a list of Apps. On click the user will be redirected to the Play Store to download this app. On successful download I have to send that apps package name to a server to validate it. How can I do that?
Asked
Active
Viewed 2,996 times
3 Answers
1
You can get all installed app in device using below code
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
}
and find package name in for loop.
Sanjay Kakadiya
- 1,622
- 1
- 15
- 30
0
I assume you want to do this at runtime, so your app can read its own package_id w/o having this hardcoded. For that you need to use PackageManager's getPackageInfo() method:
protected String getPackageName() {
try {
PackageInfo packageInfo = getPackageManager.getPackageInfo(getPackageName(), 0);
return packageInfo.applicationInfo.packageName;
} catch (Exception e) {
e.printStacktrace();
}
return null;
}
Marcin Orlowski
- 68,918
- 10
- 117
- 136
-
no not my own app info I want to get package name of app download via my app from play store – niraj Apr 21 '16 at 11:36
-
@niraj you need to rework your question as it is not clear. You said `I am developing an app which will contain a list of Apps.` - so if you got list of apps why not store Ids in that list too? – Marcin Orlowski Apr 21 '16 at 11:40
0
Use apkanalyzer, its part of the Android studio:
apkanalyzer manifest application-id path/to/apk/file.apk
michaelbn
- 6,909
- 2
- 31
- 45