OpenCV Service Intent must be explicit, Android 5.0 Lollipop

风流意气都作罢 提交于 2019-11-28 17:18:29

I think changing the android:targetSdkVersion is not a solution for very long ;) So instead I added the package name to make the intent explicit:

public static boolean initOpenCV(String Version, final Context AppContext,
        final LoaderCallbackInterface Callback) {
    AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext,
            Callback);
    Intent intent = new Intent("org.opencv.engine.BIND");
    intent.setPackage("org.opencv.engine");
    if (AppContext.bindService(intent, helper.mServiceConnection,
            Context.BIND_AUTO_CREATE)) {
        return true;
    } else {
        AppContext.unbindService(helper.mServiceConnection);
        InstallService(AppContext, Callback);
        return false;
    }
}

Maybe someone can tell an opencv comitter about this, to push a hotfix.

EDIT: From a comment below: For anyone else wondering the location of this function, it's in src/main/java/org/opencv/android/AsyncServiceHelper.java

I saw a answer here when at work, tested it and that solved the issue. Apparently it was deleted in the meanwhile. Posting it again for reference

The solution was changing: android:targetSdkVersion in the AndroidManifest.xml from 21 to 19. Can't believe it was this easy and I lost a day trying to figure it out, buy hey, thanks again to the one who posted the initial answer :)

Thanks stackoverflow!

sravanalakshmi.sunkara

I've changed OpenCV version to 3.0 and the problem was solved:

From

OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallbck);

To

OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallbck);

In order to run application at any version of android i.e. latest version.

Remove tag - android:targetSdkVersion.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!