static void Bridge_Share(string[] filesPath, string subject, string msg, string[] emails, string shareApp = "") { bool detectURL = false; if (filesPath != null) { detectURL = DetectURL(filesPath); } if (detectURL) { Instance.StartCoroutine(Instance.LoadFiles(filesPath, subject, msg, null, shareApp)); } else { if (Application.isEditor) { Debug.LogWarning("[Native Share] : You can share on your device"); return; } listenner = new GameObject("NativeShareListener", typeof(NativeShare)); #if UNITY_ANDROID string shareType = "*/*"; if (shareApp == ShareApp.Instagram) { shareType = "image/*"; } if (DetectEmailApp(shareApp)) { shareType = "message/rfc822"; } JavaShareClass.CallStatic("Native_Share", filesPath, subject, msg, emails, shareType, shareApp); #elif UNITY_IOS string filesJsonString = ""; if (filesPath != null || filesPath.Length > 0) { filesJsonString = JsonListToString(filesPath); } //Debug.Log(filesJsonString); string emailJsonString = JsonListToString(emails); Unity_Share(filesJsonString, subject, msg, emailJsonString, shareApp); #endif } }
IEnumerator EncodeImageData(Texture2D[] textures, string subject, string msg, string[] emails, string shareApp = "") { string[] filesList = new string[textures.Length]; string baseFloder = Path.Combine(Application.persistentDataPath, "NativeShare"); if (!Directory.Exists(baseFloder)) { Directory.CreateDirectory(baseFloder); } for (int i = 0; i < textures.Length; i++) { //string imageData = ""; byte[] bytes; bytes = textures [i].EncodeToPNG(); yield return(bytes); string pathSave = Path.Combine(baseFloder, "Image_" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png"); try { File.WriteAllBytes(pathSave, bytes); } catch (System.Exception ex) { Debug.Log("write file error : " + ex.Message); } finally { Debug.Log("add path : " + pathSave); filesList [i] = pathSave; } } if (Application.isEditor) { Debug.LogWarning("[Native Share] : You can share on your device"); yield break; } listenner = new GameObject("NativeShareListener", typeof(NativeShare)); #if UNITY_ANDROID string shareType = "image/*"; if (DetectEmailApp(shareApp)) { shareType = "message/rfc822"; } JavaShareClass.CallStatic("Native_Share", filesList, subject, msg, emails, shareType, shareApp); //JavaShareClass.CallStatic ("Native_ShareImageData", stringDataList, subject, msg, emails,shareType, shareApp); #elif UNITY_IOS string filesJsonString = JsonListToString(filesList); string emailJsonString = JsonListToString(emails); Unity_Share(filesJsonString, subject, msg, emailJsonString, shareApp); #endif DestroyObject(gameObject); }