Android: Check if application is installed

https://www.google.com/imgres?imgurl=https%3A%2F%2F2.bp.blogspot.com%2F-2ZMkSo7CnUs%2FWvMvSK0u9RI%2FAAAAAAAAFZA%2FzJOCZ8LUM8ol3hcHYHwVyOpc3iiYaxquACLcBGAs%2Fs1600%2FJetpack_logo.png&imgrefurl=https%3A%2F%2Fandroid-developers.googleblog.com%2F2018%2F05%2Fgoogle-io-2018-whats-new-in-android.html&docid=3_0atw3TmUdQ3M&tbnid=Ib9nmiyw87-YKM%3A&vet=10ahUKEwjApuKU7q_cAhUFdt4KHWIFDwAQMwjAASgGMAY..i&w=1400&h=1400&bih=723&biw=1440&q=%20Android&ved=0ahUKEwjApuKU7q_cAhUFdt4KHWIFDwAQMwjAASgGMAY&iact=mrc&uact=8

It attempts to fetch information about the package whose name you passed in. If you got failing result, if a was thrown, it means that no package with that name is installed.

private boolean isPackageInstalled(String packageName, PackageManager packageManager) {
try {
packageManager.getPackageInfo(packagename, 0);
return true;
} catch

--

--

🎓 “A person who never made a mistake never tried anything new.” —Albert Einstein

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Leo N

🎓 “A person who never made a mistake never tried anything new.” —Albert Einstein