Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Service Intent must be explicit, Android 5.0 Lollipop

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?

like image 504
georgej Avatar asked Dec 14 '14 14:12

georgej


2 Answers

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

like image 192
Simon Avatar answered Sep 20 '22 22:09

Simon


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!

like image 42
georgej Avatar answered Sep 16 '22 22:09

georgej