2

Is there an alternative to the getContext in UnityPlayerActivity?

I want the code as shown below.

Activity.getContext()
cahen
  • 15,807
  • 13
  • 47
  • 78
tarouMax
  • 35
  • 6

2 Answers2

4

answer from here

using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
            playerActivityContext = actClass.GetStatic< AndroidJavaObject >("currentActivity");
        }

or you can use code below from here

public class Main extends UnityPlayerActivity {

    public static Context mContext;

    @Override
    protected void onCreate(Bundle bundle)
    {
            super.onCreate(bundle);
            mContext = this;
    }
}
Alp
  • 1,863
  • 1
  • 20
  • 38
2

getContext() is not defined in an Activity. It's used in a View to get a reference to the enclosing context(an Activity).

Please read below Answer .I hope it will helps you.

Difference between getContext() , getApplicationContext() , getBaseContext() and "this"

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198