Hi,
i'm trying to get string from strings.xml.
in And_jni_bridge.pas i added this code :
function jSysInfo_GetResString (env:PJNIEnv;this:jobject;context : jObject; AResName: string): string;
Const
_cFuncName = 'getResString';
_cFuncSig = '(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;';
Var
_jMethod : jMethodID = nil;
_jParams : Array[0..1] of jValue;
_jString : jString;
_jBoolean: jBoolean;
begin
jClassMethod(_cFuncName,_cFuncSig,env,gjClass,_jMethod);
_jParams[0].l := context;
_jParams[1].l := env^.NewStringUTF(env, pchar(AResName) );
_jString := env^.CallObjectMethodA(env,this,_jMethod,@_jParams);
env^.DeleteLocalRef(env,_jParams[1].l);
Case _jString = nil of
True : Result := '';
False: begin
_jBoolean := JNI_False;
Result := String( env^.GetStringUTFChars(Env,_jString,@_jBoolean) );
end;
end;
end;
in AndroidWidget.pas i added
function jApp.GetResString(AResName: string): string;
begin
Result:= jSysInfo_GetResString(Self.Jni.jEnv, Self.Jni.jThis, Self.Jni.jActivity, PChar(AResName));
end;
in Controls.java i added this code
public String getResString(android.content.Context context, String resName) {
int id = context.getResources().getIdentifier(resName, "string", context.getPackageName());
String value = id == 0 ? "" : (String) context.getResources().getText(id);
// int id = getApplicationContext().getResources().getIdentifier("hello_world", "string", getApplicationContext().getPackageName());
// int id = getResources().getIdentifier("hello_world", "id", getPackageName());
// String value = id == 0 ? "" : (String) getApplicationContext().getResources().getString(id);
return value;
}
When i call jApp.GetResString(AResName: string): string; from a jbutton, app crash.
if i define a public variable in jApp Class in the init procedure like that, i works.
TestRes:=jSysInfo_GetResString(env, this, activity, PChar('rxml'));
How can i access the resource string dynamicly from the module (in my button) ?
ps : sorry for my english