Skip to content Skip to sidebar Skip to footer

Sending Intents From An Android-ndk Application

I am writing an native application in C++ under android, and I need to broadcast some intents. Is this possible? If you are going to point me to JNI, please give me more details, a

Solution 1:

There is a am command that you can run that will send Intents to Activities or Services.

const char *cmd = "am startservice -a %s"" --ei ars_flag 2 --ei invitationType %d"" --ei mode 1 --es ars_gadget_uuid \"%s\""" --ei ars_conn_handle %d"" --es ars_user_uuid \"%s\" --es ars_username \"%s\"";
sprintf (cmdbuffer, cmd, ...);
system (cmdbuffer);

Solution 2:

You cannot send Intents natively, this is a known limitation of the current NDK (perhaps it will be implemented in the future).

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.

Post a Comment for "Sending Intents From An Android-ndk Application"