Sending intents from an Android-NDK application

后端 未结 2 1134
野性不改
野性不改 2021-01-05 22:24

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

相关标签:
2条回答
  • 2021-01-05 23:05

    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.

    0 讨论(0)
  • 2021-01-05 23:19

    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);
    
    0 讨论(0)
提交回复
热议问题