Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, 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?

like image 439
elcuco Avatar asked Apr 03 '12 09:04

elcuco


People also ask

How do I send Intent to another app?

Sending text content putExtra(Intent. EXTRA_TEXT, "This is my text to send.") Intent sendIntent = new Intent();

How can we pass data from one activity to another using Android 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.

How do I transfer data from one Android app to another?

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.


2 Answers

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);
like image 76
SonicBison Avatar answered Nov 06 '22 21:11

SonicBison


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.

like image 43
Jake Avatar answered Nov 06 '22 21:11

Jake