void OnError(string err) { if (QRCodeManager.onErrorInvoker != null) { QRCodeManager.onErrorInvoker(err); } }
public static void SaveQRCodeToGallery(Texture2D qrCode) { string path; byte[] bytes = qrCode.EncodeToJPG(); // Call plugin only when running on real device if (Application.platform == RuntimePlatform.Android) { #if UNITY_ANDROID RefreshGalleryWrapper galleryWrapper = GameObject.FindObjectOfType <RefreshGalleryWrapper>(); if (galleryWrapper != null) { // check for permission if (!galleryWrapper.CheckPermissions()) { galleryWrapper.StoragePermissionRequest(); return; } path = galleryWrapper.GalleryPath; if (!string.IsNullOrEmpty(path)) { path = System.IO.Path.Combine(path, "QRCode_" + System.DateTime.Now.ToFileTime() + ".jpg"); try{ System.IO.File.WriteAllBytes(path, bytes); Debug.Log("Saved : " + path); } catch (System.Exception ex) { if (QRCodeManager.onErrorInvoker != null) { QRCodeManager.onErrorInvoker(ex.Message); } } galleryWrapper.RefreshGallery(path); } else { if (QRCodeManager.onErrorInvoker != null) { QRCodeManager.onErrorInvoker("Gallery path not found. Please check RefreshGalleryWrapper script attached to any gameobject and SDCard write permission in player settings."); galleryWrapper.StoragePermissionRequest(); } } } #endif } else if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.LinuxPlayer || Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor) { //save to pictures path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures); path = System.IO.Path.Combine(path, "QRCode_" + System.DateTime.Now.ToFileTime() + ".jpg"); try{ System.IO.File.WriteAllBytes(path, bytes); Debug.Log("Saved : " + path); } catch (System.Exception ex) { if (QRCodeManager.onErrorInvoker != null) { QRCodeManager.onErrorInvoker(ex.Message); } } } }