Search code examples
androidc++java-native-interface

JNI: Access to 'keySet' method with android.os.Bundle instance


I am attempting to get a list of the keys used in the extra bundle, coming from the Intent, when launching an activity. The extra bundle is being returned from the intent, but when I attempt to get the set of keys, the jmethodID is coming back null:

JNIEnv* jni = ...;
jobject extraBundle = ...; // from 'Intent.getExtras()'
jclass  bundleClass = jni->GetObjectClass(extraBundle);
jmethodID keySetMethod = jni->GetMethodID(bundleClass, "keySet", "()Ljava/util/Set"); // keySetMethod == nullptr

The keySet method comes from android.os.BaseBundle, which android.os.Bundle derives from. I have verified the signatures using java -s android.os.BaseBundle. I've tried using jni->FindClass("android/os/BaseBundle"), and using that as the jclass, but with the same results.

Is there something I'm doing incorrectly?


Solution

  • The class signature is incorrect.
    When you specify an object, you must use this format Lobject;.

    jmethodID keySetMethod = jni->GetMethodID(bundleClass, "keySet", "(V)Ljava/util/Set;");