【发布时间】:2011-11-17 14:38:45
【问题描述】:
Java 代码
在 Java 代码中,我有一个名为 IdentificationResult 的类,它有 3 个成员:
enrollmentIDenrollmentSettings-
identParams。
这是课程:
package com.vito.android.framework.service;
class IdentificationResult
{
class IdentParams {
byte[] otp;
String seedId;
}
String enrollmentID;
String enrollmentSettings;
List<IdentParams> identParams;
}
在主类中我有函数IdentificationResult GetAuthenticationStatus( ),这里是主类:
public class TokenManager
{
/* Some code goes here ... */
public IdentificationResult GetAuthenticationStatus( )
{
/* Function do some actions here ... */
return new IdentificationResult;
}
}
C++ 代码
我以这种方式从我的 C++ 代码中调用 Java 方法
void GetAuthenticationStatus( )
{
// Attach current thread.
JNIEnv *env = NULL;
m_javaVM->AttachCurrentThread( env, NULL );
if( env == NULL ) {
return -1;
}
jclass clazz = NULL;
clazz = env->GetObjectClass( m_classObject );
if( clazz == NULL ) {
return -1;
}
// Get class method.
jmethodID clazzMethod = NULL;
env->GetMethodID( clazz, "GetAuthenticationStatus", "(V;)Lcom/vito/android/framework/service/IdentificationResult;" );
if( clazzMethod == NULL ) {
return VCS_RESULT_ERROR;
}
// Call Java 'GetAuthenticationStatus' function.
jobject methodReturnObj = env->CallObjectMethod( m_classObject, clazzMethod );
// Get IdentificationResult Class from Object.
jclass identifyResultClass = env->GetObjectClass( methodReturnObj );
if( identifyResultClass == NULL )
{
return -1;
}
// Get identParams.
jfieldID fieldID = env->GetFieldID( identifyResultClass , "identParams", "***1. Question***");
if( fieldID == NULL ) {
return -1;
}
else
{
*** 2. Question ***
}
}
问题
-
为了获得
List<IdentParams>字段ID,我必须在这里写什么? -
如何获取或设置字段值?
【问题讨论】:
-
@JoopEggen 可以带来一些示例代码吗?
-
我开始打字了,但实际上你已经用完了所有需要的东西。您要么访问该字段,要么创建一个getter getIdentParams。抱歉,JNI 是一个可怕的冗长编码。 download.oracle.com/javase/1.5.0/docs/guide/jni/spec/…
标签: java android c++ c java-native-interface