Closed infosekr closed 9 years ago
I have this issue too.
It happens to me too!
I had this issue too. It seems like the Dictionary to HashMap Converter is not working properly (maybe some internal issue in JNI Bridge). I did a workaround, where I would create the AndroidJavaObject for the HashMap directly inside a function an return it, rather than using the DictionaryConverter instance and casting it.
Add this to your FlurryAndroid.cs
private static AndroidJavaObject ConvertHashMap(Dictionary<string,string> dict)
{
AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap");
IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
object[] args = new object[2];
foreach(KeyValuePair<string, string> kvp in dict)
{
using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key))
{
using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value))
{
args[0] = k;
args[1] = v;
AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(),
method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
}
}
}
return obj_HashMap;
}
_and call it like below, replacing the calls in the Wrapper where _DictionaryConverter* is used now*
using(AndroidJavaObject attrs = ConvertHashMap(parameters))
{
FlurryAgent.CallStatic<AndroidJavaObject>("logEvent", eventId, attrs, timed);
}
Seems to work for me. Note the Dictionary conversion is very similiar. The conversion code was taken from another - more outdated -Flurry Unity plugin (https://github.com/bearprada/flurry-unity-plugin), but it's essentially the same as from Mateusz.
UPDATE: Changed 'params' to 'attrs' in the call function as I forgot params was a reserved keyword in C#
Thank you for this code, looks good. Just waiting for my event to show up on Flurry but it runs for me.
On Friday, April 3, 2015 1:06 AM, rcstuber <notifications@github.com> wrote:
I had this issue too. It seems like the Dictionary to HashMap Converter is not working properly (maybe some internal issue in JNI Bridge). I did a workaround, where I would create the AndroidJavaObject for the HashMap directly inside a function an return it, rather than using the DictionaryConverter instance and casting it.Add this to your FlurryAndroid.cs private static AndroidJavaObject ConvertHashMap(Dictionary<string,string> dict) { AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap")
IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
object[] args = new object[2];
foreach(KeyValuePair<string, string> kvp in dict)
{
using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key))
{
using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value))
{
args[0] = k;
args[1] = v;
AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(),
method_Put, AndroidJNIHelper.CreateJNIArgArray(args));
}
}
}
return obj_HashMap;
}and call it like below, replacing the calls in the Wrapper where *DictionaryConverter** is used now*using(AndroidJavaObject params = ConvertHashMap(parameters))
{
FlurryAgent.CallStatic
Fixed, there was an error with AndroidJavaObject inheritance.
E/Unity (13383): Exception: JNI: Unknown signature for type 'Analytics.FlurryAndroid+DictionaryConverter' (obj = Analy tics.FlurryAndroid+DictionaryConverter) instance
Looks like it's having trouble handling a Dictionary<string,string> for the parameters parameter. LogEvent(eventName) seems to work (haven't seen my event on the flurry site yet)