Documente Academic
Documente Profesional
Documente Cultură
Stack Overflow
log in
44
android-applicationinfo
How can I learn whether a particular package or application - say, "com.android.abc" - exists on my Android device?
share
5 Answers
95
Asked
Jul 20 '11 at 8:07
Edited
Mar 5 '14 at 10:24
Order By
Votes
import com.android.content.pm.PackageManager;
// ...
public boolean isPackageExisted(String targetPackage){
List<ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
packages = pm.getInstalledApplications(0);
for (ApplicationInfo packageInfo : packages) {
if(packageInfo.packageName.equals(targetPackage))
return true;
}
return false;
import com.android.content.pm.PackageManager;
public boolean isPackageExisted(String targetPackage){
PackageManager pm=getPackageManager();
try {
PackageInfo info=pm.getPackageInfo(targetPackage,PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return true;
}
share
Thanks Rasel, I was looking for this only. Thank U very much. brig Jul 20 '11 at 8:32
Answered
Jul 20 '11 at 8:18
Edited
Apr 22 '15 at 14:30
share
You should use PackageManager's function called getInstalledPackages() to get the list of all installed packages and the search for the
one you are interested in. Note that package name is located in PackageInfo.packageName field.
share
Answered
Jul 20 '11 at 8:15
Answered
Dec 7 '13 at 23:57
share
Answered
Jun 8 '15 at 11:40
Since some devices have reported that the "getInstalledPackages" can cause TransactionTooLargeException (check here, here and
here), I think you should also have a fallback like I did below.
This issue was supposed to be fixed on Android 5.1 (read here), but some still reported about it.
share
Your Answer
Answered
Mar 21 at 7:52
log in
or
Name
By posting your answer, you agree to the privacy policy and terms of service.
meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app
2016 Stack Exchange, Inc