OpenCV服务意图必须明确,Android 5.0 Lollipop [英] OpenCV Service Intent must be explicit, Android 5.0 Lollipop
问题描述
我正在为使用OpenCV的本科学历构建此应用程序.一切正常,直到我将手机的Android更新到5.0.
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:服务意图必须是明确的:意图{act = org.opencv.engine.BIND}
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=org.opencv.engine.BIND }
我已阅读并告知自己有关Android 5.0中隐式意图的新限制,但是如何解决这个问题才能使OpenCV正常工作?
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?
我可以修改OpenCV SDK中的 AsyncServiceHelper.java 文件以尝试解决此问题,但是我如何才能按顺序获取需要运行的OpenCV服务的Class对象使用明确的意图?
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?
也许这种方法是死路一条,但是还有其他方法吗?或者我唯一的选择是对OpenCV SDK的更新,还是对我设备上的Android版本进行降级?
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?
推荐答案
我认为更改android:targetSdkVersion并不是很长时间的解决方案;)因此,我添加了程序包名称以使意图明确:
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;
}
}
也许有人可以告诉opencv提交者有关此问题的信息,以推送修补程序.
Maybe someone can tell an opencv comitter about this, to push a hotfix.
从下面的评论中:对于其他想知道此函数位置的人,它在src/main/java/org/opencv/android/AsyncServiceHelper中. Java
From a comment below: For anyone else wondering the location of this function, it's in src/main/java/org/opencv/android/AsyncServiceHelper.java
这篇关于OpenCV服务意图必须明确,Android 5.0 Lollipop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!