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, as I am not sure how this is done :)
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.
Is there a better way?
Sending text content putExtra(Intent. EXTRA_TEXT, "This is my text to send.") Intent sendIntent = new Intent();
Using Intents This example demonstrate about How to send data from one activity to another in Android using intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
There are three ways your app can receive data sent by another app: An Activity with a matching intent-filter tag in the manifest. One or more ChooserTarget objects returned by your ChooserTargetService. Sharing Shortcuts published by your app.
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With