简体   繁体   English

Android检查已安装的应用程序失败

[英]Android check installed app failed

In my program there is check if OpenCV Manager app installed. 在我的程序中,检查是否安装了OpenCV Manager应用程序。 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? 但是在Samsung Galaxy Xcover 3手机上,它始终返回true ,因此在带有OpenCV摄像头预览的表格中, package not found, install? message and file not found on accept installation. 接受安装时file not found消息和file not found

What is wrong with galaxy phone? 银河电话怎么了? Or with my code? 还是我的代码?

UPDATE 更新

This link makes me sad. 这个链接让我很难过。 Does that mean there is no solution? 这是否意味着没有解决方案?

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;
        }

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. 我在Activity类的静态部分中通过initAsync将OpenCV初始化initAsyncinitDebug I have OpenCV library projects linked to my project, so it works for me. 我有链接到我的项目的OpenCV库项目,所以它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM