在JNI中难免会遇到中文乱码的问题,这里是解决部分乱码的一个简单示例,留作备忘
public class HelloWorld1 extends Activity {
/** Called when the activity is first created. */
static {
System.loadLibrary("Hello");
}
public native String helloFromJNI();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
//按钮的点击事件
public void click (View view){
try {
String s = helloFromJNI();
String s1= new String(s.getBytes("iso8859-1"), "UTF-8" ) ; //主要是这里的处理,处理从接口中拿到的String
Toast.makeText(this, s , 1).show();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}