#include <jni.h>
JNIEXPORT jstring JNICALL Java_com_app_test_TestJNIActivity_getstr(JNIEnv* env, jobject Thiz,jstring host){
return host;
}
package com.app.test;
import java.io.UnsupportedEncodingException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestJNIActivity extends Activity {
static{
System.loadLibrary("SocketClient");
}
private native String getstr(String str);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView tv=(TextView)findViewById(R.id.tv);
Button btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String str=new String(getstr("中国四川成都武侯区高新区").getBytes("utf-16"),"utf-16");
tv.setText("native函数传来的值:"+str+" 原始值:"+"中国四川成都武侯区高新区");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}