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! :)
Answer by mgilbert · Sep 09, 2019 at 05:16 AM
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);
//...
}
}
Your answer
Follow this Question
Related Questions
Unity to Native Code Calls Wrong Function 0 Answers
Android Plugin - .aar file missing R$raw reference 0 Answers
Native android plugin stop working when changing scenes 0 Answers
How to get the low level rendering plugin working on Android? 1 Answer
Using Android Native Classes in Unity3d / File open Dialog 0 Answers