Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check whether Application is installed or not on an Android device

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 209
    Comment on it

    There are two ways to know that the particular application is installed in your android device or not.

    1st way:-

    In first way we get the list of installed application and check whether the targeted package name (package of the application that we want to check) is present or not. If the target package is present that means the particular application is installed otherwise not.

    Code:-

    public boolean isApplicationInstalled(String targetPackage) {
        List<ApplicationInfo> packages;
        PackageManager pm;
    
        pm = getPackageManager();
        packages = pm.getInstalledApplications(0);
        for (ApplicationInfo packageInfo : packages) {
            if (packageInfo.packageName.equals(targetPackage)) {
                // Application found
                return true;
            }
        }
        // Application not found
        return false;
    }
    

    2nd way:-

    In a second way we check that the particular package information is available or not without getting the list of all apps installed on device and itterating through them. If the information is available that means application is installed otherwise NameNotFoundException will raise which means application is not installed.

    Code:-

    public boolean isApplicationInstalled(String targetPackage) {
        PackageManager pm = getPackageManager();
        try {
            PackageInfo info = pm.getPackageInfo(targetPackage, PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            // Appllication not found
            return false;
        }
        // Application found
        return true;
    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: