0

In my program there is check if OpenCV Manager app installed. I got idea from this answer, here is my code:

public static boolean isAppInstalled(Context cnt, String packName) {
    PackageManager pm = cnt.getPackageManager();
    try {
        pm.getPackageInfo(packName, PackageManager.GET_ACTIVITIES);
    }
    catch (PackageManager.NameNotFoundException e) {
        return false;
    }
    return true;
}

It is calling from:

private boolean isOpenCVInstalled() {
    return GlobalFunctions.isAppInstalled(this, "org.opencv.engine");
}

On my phone and tablet it works fine. But on Samsung Galaxy Xcover 3 phone it is always returns true, so in form with OpenCV camera preview I get package not found, install? message and file not found on accept installation.

What is wrong with galaxy phone? Or with my code?

UPDATE

This link makes me sad. Does that mean there is no solution?

Community
  • 1
  • 1
Ircover
  • 2,406
  • 2
  • 22
  • 42

2 Answers2

0

This method works for me:

public boolean isAppInstalled(Context ctx,String packageName) {
            PackageManager pm = ctx.getPackageManager();
            List<ApplicationInfo> apps = pm
                    .getInstalledApplications(PackageManager.GET_META_DATA);

            for (ApplicationInfo app : apps) {
                if (app.packageName.equals(packageName)) {
                    return true;
                }
            }
            return false;
        }
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
0

Well, I believe this link.

Now with my solution it is not important. I changed OpenCV initialization by initAsync to initDebug in static section of Activity class. I have OpenCV library projects linked to my project, so it works for me.

Ircover
  • 2,406
  • 2
  • 22
  • 42