Example #1
0
        static void Init()
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            lock (InitLock)
            {
                if (!ReferenceEquals(_instance, null))
                {
                    return;
                }

                var instances = FindObjectsOfType <GoodiesSceneHelper>();

                if (instances.Length > 1)
                {
                    Debug.LogError(typeof(GoodiesSceneHelper) + " Something went really wrong " +
                                   " - there should never be more than 1 " + typeof(GoodiesSceneHelper) +
                                   " Reopening the scene might fix it.");
                }
                else if (instances.Length == 0)
                {
                    var singleton = new GameObject();
                    _instance           = singleton.AddComponent <GoodiesSceneHelper>();
                    singleton.name      = "GoodiesSceneHelper";
                    singleton.hideFlags = HideFlags.HideAndDontSave;

                    DontDestroyOnLoad(singleton);

                    Debug.Log("[Singleton] An _instance of " + typeof(GoodiesSceneHelper) +
                              " is needed in the scene, so '" + singleton.name +
                              "' was created with DontDestroyOnLoad.");
                }
                else
                {
                    Debug.Log("[Singleton] Using _instance already created: " + _instance.gameObject.name);
                }
            }
        }
        public static AndroidJavaObject GetUriFromFilePath(string saveFilePath)
        {
            AndroidJavaObject uri;

            if (AGDeviceInfo.SDK_INT >= AGDeviceInfo.VersionCodes.N)
            {
                // Reference: http://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed
                using (var c = new AndroidJavaClass(FileProviderClass))
                {
                    var provider = AGDeviceInfo.GetApplicationPackage() + ".multipicker.fileprovider";
                    uri = c.CallStaticAJO("getUriForFile", AGUtils.Activity, provider, AGUtils.NewJavaFile(saveFilePath));
                }
            }
            else
            {
                uri = AndroidUri.FromFile(saveFilePath);
            }

            return(uri);
        }
        public static AndroidJavaObject SaveShareImageToExternalStorage(Texture2D tex2D)
        {
            // aTODO update : http://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed
            string            saveFilePath = SaveImageToPictures(tex2D, GoodiesShareImageFileName, GoodiesFileFolder, ImageFormat.PNG);
            AndroidJavaObject uri;

            if (AGDeviceInfo.SDK_INT >= AGDeviceInfo.VersionCodes.N)
            {
                using (var c = new AndroidJavaClass(FileProviderClass))
                {
                    var provider = AGDeviceInfo.GetApplicationPackage() + ".multipicker.fileprovider";
                    uri = c.CallStaticAJO("getUriForFile", AGUtils.Activity, provider, AGUtils.NewJavaFile(saveFilePath));
                }
            }
            else
            {
                uri = AndroidUri.FromFile(saveFilePath);
            }
            return(uri);
        }