OpenCV Service Intent must be explicit, Android 5.0 Lollipop

georgej picture georgej · Dec 14, 2014 · Viewed 12.2k times · Source

I'm building this application for my bachelor's diploma that uses OpenCV. Everything was going fine until I updated my phone's Android to 5.0.

After the update my project stopped working, because of this:

java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=org.opencv.engine.BIND }

I have read and informed myself about the new restrictions regarding implicit intents in Android 5.0, but how can I get around this in order for OpenCV to work?

I could modify the AsyncServiceHelper.java file in the OpenCV SDK in order to try and fix this, but how could I get the Class object of the OpenCV service that needs to be run, in order to use an explicit intent?

Or maybe this approach is a dead end, but are there any other approaches to this, or are my only options either an update to the OpenCV SDK, or to downgrade the Android Version on my device?

Answer

Simon picture Simon · Feb 19, 2015

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