georgej
georgej

Reputation: 468

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?

Upvotes: 17

Views: 12496

Answers (4)

sravanalakshmi.sunkara
sravanalakshmi.sunkara

Reputation: 1161

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

Upvotes: 0

Simon
Simon

Reputation: 13283

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

Upvotes: 50

AnkitRox
AnkitRox

Reputation: 544

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

Remove tag - android:targetSdkVersion.

Upvotes: -5

georgej
georgej

Reputation: 468

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!

Upvotes: 7

Related Questions