public static List <Bitmap> getBitmapList(IntPtr list) { #if VERBOSE_LOGGING Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name)); #endif JNIFind(); if (_jcOuyaUnityPlugin == IntPtr.Zero) { Debug.LogError("_jcOuyaUnityPlugin is not initialized"); return(null); } if (_jmGetBitmapArray == IntPtr.Zero) { Debug.LogError("_jmGetBitmapArray is not initialized"); return(null); } IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetBitmapArray, new jvalue[] { new jvalue() { l = list } }); if (result == IntPtr.Zero) { Debug.LogError("_jmGetBitmapArray returned null"); return(null); } List <Bitmap> items = new List <Bitmap>(); #if VERBOSE_LOGGING Debug.Log("Invoking AndroidJNI.FromObjectArray..."); #endif IntPtr[] resultArray = AndroidJNI.FromObjectArray(result); #if VERBOSE_LOGGING Debug.Log("Invoked AndroidJNI.FromObjectArray."); #endif foreach (IntPtr ptr in resultArray) { #if VERBOSE_LOGGING Debug.Log("Found Bitmap making Global Ref..."); #endif IntPtr globalRef = AndroidJNI.NewGlobalRef(ptr); AndroidJNI.DeleteLocalRef(ptr); #if VERBOSE_LOGGING Debug.Log("Made global ref for Bitmap."); #endif Bitmap item = new Bitmap(globalRef); #if VERBOSE_LOGGING Debug.Log("Deleting old bitmap reference..."); #endif items.Add(item); } #if VERBOSE_LOGGING Debug.Log("Deleting bitmap list reference..."); #endif AndroidJNI.DeleteLocalRef(result); return(items); }
/// <summary> /// Gets all secondary storages and return only available ones. /// </summary> public static List <string> GetAvailableSecondaryStorages() { List <string> storages = new List <string> (); #if !IGNORE_ANDROID_SCREENSHOT try { // Get methods AndroidJavaClass classPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject objActivity = classPlayer.GetStatic <AndroidJavaObject> ("currentActivity"); IntPtr getExternalMediaDirsMethod = AndroidJNI.GetMethodID(objActivity.GetRawClass(), "getExternalMediaDirs", "()[Ljava/io/File;"); // IntPtr obj_context = AndroidJNI.FindClass ("android/content/ContextWrapper"); // IntPtr getExternalMediaDirsMethod = AndroidJNIHelper.GetMethodID (obj_context, "getExternalMediaDirs", "()[Ljava/io/File;"); // Get files array IntPtr filesPtr = AndroidJNI.CallObjectMethod(objActivity.GetRawObject(), getExternalMediaDirsMethod, new jvalue[0]); // Get files from array IntPtr[] files = AndroidJNI.FromObjectArray(filesPtr); // Parse files for (int i = 0; i < files.Length; ++i) { // Get file path IntPtr getPathMethod = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(files [i]), "getPath", "()Ljava/lang/String;"); IntPtr pathPtr = AndroidJNI.CallObjectMethod(files [i], getPathMethod, new jvalue[] { }); string path = AndroidJNI.GetStringUTFChars(pathPtr); AndroidJNI.DeleteLocalRef(pathPtr); // Check path is available AndroidJavaClass environment = new AndroidJavaClass("android.os.Environment"); IntPtr getExternalStorageStateMethod = AndroidJNI.GetStaticMethodID(environment.GetRawClass(), "getExternalStorageState", "(Ljava/io/File;)Ljava/lang/String;"); jvalue[] args = new jvalue[1]; args [0].l = files [i]; IntPtr statePtr = AndroidJNI.CallStaticObjectMethod(environment.GetRawClass(), getExternalStorageStateMethod, args); string state = AndroidJNI.GetStringUTFChars(statePtr); AndroidJNI.DeleteLocalRef(statePtr); if (state == "mounted") { storages.Add(path); } } } catch (System.Exception e) { Debug.LogError("AndroidUtils: Error getting secondary external storage directory: " + e.Message); } #endif return(storages); }
public static List <string> getStringList(IntPtr list) { #if VERBOSE_LOGGING Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name)); #endif JNIFind(); if (_jcOuyaUnityPlugin == IntPtr.Zero) { Debug.LogError("_jcOuyaUnityPlugin is not initialized"); return(null); } if (_jmGetStringArray == IntPtr.Zero) { Debug.LogError("_jmGetStringArray is not initialized"); return(null); } IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetStringArray, new jvalue[] { new jvalue() { l = list } }); if (result == IntPtr.Zero) { Debug.LogError("_jmGetStringArray returned null"); return(null); } List <string> items = new List <string>(); IntPtr[] resultArray = AndroidJNI.FromObjectArray(result); AndroidJNI.DeleteLocalRef(result); foreach (IntPtr ptr in resultArray) { string item = AndroidJNI.GetStringUTFChars(ptr); AndroidJNI.DeleteLocalRef(ptr); items.Add(item); } return(items); }
public static List <OuyaMod> getOuyaContentPublishedResults() { #if VERBOSE_LOGGING Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name)); #endif JNIFind(); if (_jcOuyaUnityPlugin == IntPtr.Zero) { Debug.LogError("_jcOuyaUnityPlugin is not initialized"); return(null); } if (_jmGetOuyaContentPublishedResults == IntPtr.Zero) { Debug.LogError("_jmGetOuyaContentPublishedResults is not initialized"); return(null); } IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetOuyaContentPublishedResults, new jvalue[0] { }); if (result == IntPtr.Zero) { Debug.LogError("_jmGetOuyaContentPublishedResults returned null"); return(null); } List <OuyaMod> ouyaMods = new List <OuyaMod>(); IntPtr[] resultArray = AndroidJNI.FromObjectArray(result); foreach (IntPtr ptr in resultArray) { IntPtr globalRef = AndroidJNI.NewGlobalRef(ptr); AndroidJNI.DeleteLocalRef(ptr); OuyaMod ouyaMod = new OuyaMod(globalRef); ouyaMods.Add(ouyaMod); } AndroidJNI.DeleteLocalRef(result); return(ouyaMods); }