从一个Android NDK应用程序发送意图 [英] Sending intents from an Android-NDK application
问题描述
我在C ++下的Android编写一个原生应用,我需要一些广播意图。这可能吗?
I am writing an native application in C++ under android, and I need to broadcast some intents. Is this possible?
如果你要我指向JNI,请给我更多的细节,因为我不知道如何做到这一点:)
If you are going to point me to JNI, please give me more details, as I am not sure how this is done :)
什么是否具有NDK守护程序和Java的Android的服务之间的命名管道,这是不可能的,我会做的。 NDK的守护程序将数据写入命名管道,然后Java的Android的服务将发出意图。
What I will do if this is not possible is having a named pipe between the NDK daemon and a Java-Android-Service. The NDK-daemon will write to the named pipe and then the Java-Android-Service will issue the intent.
有没有更好的办法?
推荐答案
您不能发送意图本身,这是当前NDK(也许这将在未来实现)的一个已知的限制。
You cannot send Intents natively, this is a known limitation of the current NDK (perhaps it will be implemented in the future).
所以,你所要做的就是用JNI作出上调,Java的,每当你想广播一个Intent(谷歌JNI和向上调用,如果你需要知道如何做到这一点),并有Java的code,它创建和发送意图。所以,如果你开始通过Java活动您的应用程序并调用通过JNI本地code,只需在Java中实现另一种方法,可以收到你的上行调用。我不知道你有多么JNI知道,但维基百科的信息应该让你开始不够好。
So what you have to do is to use JNI to make an upcall to Java whenever you want to broadcast an Intent (google JNI and upcall if you need to know how this is done), and have Java code that creates and sends the Intent. So if you're starting your application through a Java Activity and calling the native code through JNI, simply implement another method in Java that can receive your upcall. I don't know how much JNI you know, but the wikipedia information should get you started well enough.
这篇关于从一个Android NDK应用程序发送意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!