我目前正在使用原生c ++代码处理(现有的)Android应用程序。 我想向另一个收听BroadcastReceiver的Android Java应用发送广播。 接收应用程序还在运行,但我无法弄清楚如何直接或通过将值发送到Java代码并从Java广播它来从JNI代码广播数据。
我希望我的解释清楚。 有人可以帮我解决这个问题吗?
谢谢!
I'm currently working on (an existing) Android app using native c++ code. I want send a broadcast to another Android Java app listening to a BroadcastReceiver. The receiving app is yet working, but I can't figure out how to broadcast data from JNI code either directly or by sending the values to java code and them broadcasting it from Java.
I hope my explanaion is clear. Can someone help me on how to accomplish this?
Thanks!
最满意答案
最简单的方法可能是在Java中编写它并编写一个JNI回调来调用该Java函数。 如果您确实需要在C中执行此操作,则需要使用JNI创建Intent,然后设置intent的action和extras,然后使用JNI调用活动的sendBroadcast方法来实际发送它。 它有很多样板JNI代码,所以我试着避免它。
The easiest way is probably to do it in Java and write a JNI callback to call that Java function. If you do need to do it in C, you'll need to use JNI to create an Intent, then to set the action and extras of the intent, then use JNI to call the sendBroadcast method of your activity to actually send it. Its a lot of boilerplate JNI code, so I'd try to avoid it.
更多推荐
发布评论