androidc++java-native-interfaceandroid-sourceandroid-framework

How to call Android framework c++ functions in JNI?


I need to call this function virtual sp<IOMX> getOMX(); in /framework/base/media/libmediaplayerservice/MediaPlayerService.h to get some information in Android. So I use JNI to do it. However, in the C++ code, can I call the Android framework C++ functions like getOMX() ? How to do? Thanks.


Solution

  • When you use any APIs that are not "stable" in terms of the NDK document, you are playing with fire. But when it comes to getOMX(), the fire is not very hot.

    You can get the headers from the AOSP source git, e.g.

    git clone https://android.googlesource.com/platform/frameworks/av
    

    and #include "frameworks/av/include/media/IMediaPlayerService.h"

    You will also need to provide the system .so files to linker, in this case - libmediaplayerservice.so. You can use command

    adb pull /system/lib/libmediaplayerservice.so .
    

    to get this library from an emulator or from a physical device.