Android plug-in - how to convert AndroidJavaObject to String[]?
Hi guys,
I am having trouble converting a valid AndroidJavaObject to a String[]. Or am I doing something wrong?
Making an Android lib plug-in, I am having trouble reading the output of a function. The return type is ArrayList from my java class.
public static ArrayList<String> getGrantedPermissions(Context c, final String appPackage) {
ArrayList<String> granted = new ArrayList<String>();
try {
PackageInfo pi = c.getPackageManager().getPackageInfo(appPackage, PackageManager.GET_PERMISSIONS);
for (int i = 0; i < pi.requestedPermissions.length; i++) {
if ((pi.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
granted.add(pi.requestedPermissions[i]);
Log.i("Unity",pi.requestedPermissions[i]);
}
}
} catch (Exception e) {
}
return granted;
}
Now from C# I am using
AndroidJavaObject j = ajc.CallStatic<AndroidJavaObject>("getGrantedPermissions", new object[2] { jo, Application.identifier});
if (j.GetRawObject().ToInt32() != 0)
{
Debug.Log("valid");
String[] res = AndroidJNIHelper.ConvertFromJNIArray<String[]>(j.GetRawObject());
foreach (var s in res)
{
Debug.Log("perm " + s);
}
}
else
{
Debug.Log("Error null ptr");
}
Any hint will be welcome~ Currently the logcat gives me
JNI DETECTED ERROR IN APPLICATION: jarray argument has non-array type: java.util.ArrayList in call to GetArrayLength from boolean com.unity3d.player.UnityPlayer.nativeRender()
Your answer
Follow this Question
Related Questions
FitnessSensorService not being started by Android OS 1 Answer
CommandInvokationFailure: Failed to re-package resources Mapbox/FB 0 Answers
Unity plug-in/ Support SDK or 3rd party plug-in to handle Huawei Dynamic ability SDK. 0 Answers
problem on rendertexture handling on Android 0 Answers
Unity APK doesn't load on Android. 0 Answers