android JNI java与C++传递String数组(引用类型)

android java

public class MainActivity extends AppCompatActivity {

    static{
        System.loadLibrary("myndk");
    }

    private TextView textView;

    public native String getStr(String[] oa);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (TextView)findViewById(R.id.text);
        String[] oa={"你呀","我呀"};
        textView.setText(getStr(oa));
    }
}



C++ (这里是支持C++11的)

#include 
#include 

JNIEXPORT jstring JNICALL
Java_com_myndk_MainActivity_getStr(JNIEnv *env, jobject instance,jobjectArray oa)
{
    jsize size = env->GetArrayLength(oa);
    for(int i=0;iGetObjectArrayElement(oa,i);
        std::string sstr = (std::string)env->GetStringUTFChars(obj,NULL);//得到字符串

    }
    std::string str="NDK";
    return env->NewStringUTF(str.data());
}


你可能感兴趣的:(Android,C++)