Android NDK limitations?

前端 未结 4 1282
广开言路
广开言路 2021-02-05 12:13

I have a question about the limitations of what you can do in native code on the Android platform.

Basically I have developed a library in native C code that uses UDP so

相关标签:
4条回答
  • 2021-02-05 12:49

    The Native Android API is a nice article for NDK.

    is it possible to just use the Java for the GUI and then all processing in native code?

    Yes. And you need to set appropriate permissions to your AndroidManifest.

    record audio, play it,

    You need to use OpenSL ES API for recording and playing audio in the native side. It means your application should be for Android 2.3 or later.

    Or, NVIDIA provides a framework that allow we to be able to develop using C++ for Android events, sensors, audio and so on even though for Android 2.2 or earlier.

    Tegra Resources - Android SDK & NDK sample applications and documentation

    0 讨论(0)
  • 2021-02-05 12:50

    You can do pretty much anything you want in native code, but the only OS-level thing really supported is OpenGL, OpenSL, and some number-crunching libraries (compression, math, etc).

    However, at any time you're free to use the JNI to call a Java method, so you could use the standard Android API for networking (classes like Socket, etc). Obviously, since the call is going through the Java API, all the normal Android permissions apply (like android.permission.INTERNET).

    EDIT: As elaborated in the comments, the standard libraries that are part of the NDK do have support for sockets.

    0 讨论(0)
  • You may like to check out csipsimple which is a example of using the pjsip sip library (which is written in C) in a java android application.

    I haven't looked into how it does the sockets communication but it should give you a more complete example of what you are trying to do.

    0 讨论(0)
  • 2021-02-05 13:08

    You still need your application to have permissions. For example, your native sockets will not work without android.permission.INTERNET in the manifest.

    <manifest xlmns:android...>
     ...
     <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    </manifest>
    

    Another option is to create the socket at the Java layer and pass it down. Here's an example of interacting with the socket in native land, see the method org_..._OpenSSLSocketImpl_connect():

    http://www.netmite.com/android/mydroid/dalvik/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp

    0 讨论(0)
提交回复
热议问题