Cannot call a native Android method in the latest versions of Unity...?

Hi! The following code used to work in Unity versions 2018.x.x but it seems like the AndroidJavaObject::Call method doesn’t work anymore in 2019.1.0? When attempting to build for Android, the line gives an error which states that Call returns void… Am I wrong in assuming it should return an AndroidJavaObject here?

using(AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){
	using(AndroidJavaObject context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")){
		AndroidJavaObject[] externalFilesDirs = context.Call<AndroidJavaObject[]>("getExternalFilesDirs", null);
		//...
	}
}

The error:

error CS0029: Cannot implicitly convert type 'void' to 'UnityEngine.AndroidJavaObject[]'

Thanks! :slight_smile:

It looks like you need to explicitly cast the “null” now:

 using(AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){
     using(AndroidJavaObject context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")){
         AndroidJavaObject[] externalFilesDirs = context.Call<AndroidJavaObject[]>("getExternalFilesDirs", (object[])null);
         //...
     }
 }