Android jni广播到java(Android jni broadcast to java)

编程入门 行业动态 更新时间:2024-10-25 23:26:20
Android jni广播到java(Android jni broadcast to java)

我目前正在使用原生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.

更多推荐

本文发布于:2023-07-31 09:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1341925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jni   Android   broadcast   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!