0

I work on a library directly installed in the Android system, and executed by the AudioFlinger (the android system mediaserver), and build in C++ with the AOSP, not with the JNI/NDK. I need to get an event from this library in a classic java application.

Is it possible to send a system intent from my library?

I've tested am broadcast -a com.myIntent and it works in the command line but not from inside my library.

UPDATE: it IS a permission problem, because activating the permissive mode allow the intent to be catched by my java application. cf Sending an intent from c++ to java in Android 5.0.1_r1

Community
  • 1
  • 1
Ben.
  • 45
  • 6
  • Would [calling `am` sufficient](http://stackoverflow.com/a/10965444/224671) for you? – kennytm Mar 03 '17 at 17:35
  • you mean it is possible to send an intent through this command-line, like system("am broadcast myIntent") ? I'll try this and update my question if it works :) – Ben. Mar 03 '17 at 17:43
  • Yes. (Feel free to put that into the answer if it works) – kennytm Mar 03 '17 at 17:47
  • It is working from the command line: `C:\>adb shell am broadcast -a com.myIntent Broadcasting: Intent { act=com.myIntent } Broadcast completed: result=0` But I can't get it from my C++ with: `system("am broadcast -a com.myIntent ");` – Ben. Mar 06 '17 at 15:37
  • Are you running your C++ program as the `shell` user (uid 2000)? – kennytm Mar 06 '17 at 15:42
  • nope: it is a library executed by the audioflinger (system android mediaserver). – Ben. Mar 06 '17 at 15:50
  • Ah, perhaps you should add this information to the question. – kennytm Mar 06 '17 at 15:53

1 Answers1

0

If when you state it works in permissive mode, you mean you have a rooted device and proceed with adb shell setenforce 0. Means you have SELinux problem, and will not be allowed by the manufacturer to do that in your library. Even if you modify the SELinux policy in that device, you will most probably have the same problem in many other Android devices in the market.

EDIT

If this meets your needs, you can launch that command from within your code. Follow how to run adb shell commands from android code? on that other matter.

Community
  • 1
  • 1
Olaia
  • 2,172
  • 25
  • 27