【发布时间】:2020-05-10 14:56:14
【问题描述】:
所以我有这个 CanvasView,它显示了我的应用程序的调试信息。它基本上是具有透明背景的叠加视图,因此画布中绘制的所有内容都漂浮在屏幕中。由于我需要来自返回 wchar_t* 的本机 c++ 的一些信息,我该如何使用 env->NewString,因为 android 现在使 wchar_t 为 4 个字节,而 jchar 为 2 个字节?
在我的库中调用本机 c++ 函数的 java 代码:
private static String get_Name();
private class CanvasView extends View{
public CanvasView(Context context){
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paintText = new Paint();
paintText.setStyle(Paint.Style.FILL);
paintText.setColor(Color.WHITE);
paintText.setShadowLayer(5.5f, 0, 0, Color.BLACK);
paintText.setTextSize(convertSizeToDp(7.5f));
paintText.setTextAlign(Paint.Align.LEFT);
paintText.drawText(get_Name(), x, y, paintText);
// the rest of the code
// ...
}
}
get_Name 基本上返回一个来自NewString((const jchar* )myWchar, myLen)的jstring
当调用NewString 时,返回结果有时是非 unicode 字符串,甚至我的应用程序崩溃。
【问题讨论】:
-
这能回答你的问题吗? Android Canvas.drawText
-
@TruthSeeker 不,我的问题是将 wchar_t* 转换为 jstring。
标签: android c++ java-native-interface