Hello, is it possible to get reference to the Application class?
I will try to explain a bit more, for example I want to implement Flurry Analytics which is requires to pass application class ref to the Flurry SDK.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// init Flurry
FlurryAgent.init(this, YOUR_FLURRY_API_KEY);
//....
}
}
In order to do this I can only try to override default app application class with my own, and specify this in the AndroidManifest.xml
This approach is defiantly working, but if another plugin in my project will try to do the same it will get unresolvable conflict, that’s why I am asking if there is a way to get reference to Application class, in the same way as we can get reference to the current Main Activity.
You can get a reference to the Application from the main activity, but if you do so from Unity (without diving into the native Android level), you won’t be able to run this in the Application’s onCreate method (only later on, when Unity loads).
To do so, you can use this code (didn’t test it, but i think it should work):
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
// get activity
var activity = actClass.GetStatic<AndroidJavaObject>("currentActivity");
// get application
var application = activity.Call<AndroidJavaObject>("getApplication");
// init Flurry: FlurryAgent.init(this, YOUR_FLURRY_API_KEY);
using (var flurryClass = new AndroidJavaClass("com.flurry.android.FlurryAgent"))
{
flurryClass.CallStatic("init", application, "API_KEY");
}
}
I think you should create your own Application class though, just like their docs require.